I want to replace all external url except my website link in my article . So that original link to the external site is get encrypted/ masked/ rewritten.
For example:
original link: www.google.com rewrite it to: www.mydomain.com/goto/google.com
I tried DOMDocument and it has error:
Warning: DOMDocument::loadHTML(): Attribute target redefined in Entity, line: 1 in [...][...] on line 20
I tried
<?php
$html ='1224 <a href="http://www.google.com">google</a> 567';
$tracking_string = 'http://example.com/goto/';
$html = preg_replace('#(<a[^>]+href=")(http|https)([^>" ]+)("?[^>]*>)#is','\\1'.$tracking_string.'\\2\\3\\4',$html);
echo $html;
it replaces all links including my website links