Forum Moderators: coopster
Need the regular expression for modifying hrefs(so not other urls in images etc)
Example change
<a href=http://www.site1.com> to <a href="www.site2.com?q=http://www.site1.com">
Need it to work with urls that use relative paths so change
<a href="/"> to <a href="www.site2.com?q=/">
Be nice if it worked with all possible urls
<a href="http://www.site1.com">
< a href=‘http://www.site1.com’>
<a href=http://site1.com>
Etc
I’ve found a few similar examples and near working bits of code but i rarely use preg_replace and don’t know enough to get them to work.
Any help with this will be greatly appreciated thanks.
$content = <<<EOQ
<a href="http://www.google.com"></a>
<a href=http://www.ala.com></a>
EOQ;
$content = preg_replace('#(<a[^>]+href="?)([^>" ]+)("?[^>]*>)#is','\\1http://www.site2.com?q=\\2\\3', $content);
print $content;
[edited by: eelixduppy at 12:37 pm (utc) on Mar. 20, 2008]
[edit reason] disabled smileys [/edit]