|
Posted by Hero Wanders on 08/26/05 14:18
Hello!
> <a href="www.abc.com">ABC</a>
> <a href="www.xyz.com">www.xyz.com</a>
>
> I'm looking for a script that replaces the part within the HTML tag
> (www.abc.com and www.xyz.com) with another link (in my case a
> redirect), without affecting the part with "www.xyz.com: enclosed by
> the tags.
This should work:
<?php
$link = '<a href="http://www.google.com" target="_bla">foobar</a>';
$my_url = 'http://www.example.com/redirect.php?url=$1';
echo preg_replace('/(?<=\<a href\=\")([^\"]+)(?=\")/', $my_url, $link);
?>
Of course $link could be any text containing links.
Greetings,
Hero Wanders
Navigation:
[Reply to this message]
|