Hello!
Example:
<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.
I've tried something myself which replaces the url's, but all strings
that resemble an url
function replaceUrls($text)
{
global $BASE_URL;
$pattern = "[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]";
$replacement = "\\0";
$text = eregi_replace($pattern, $replacement, $text);
$endoftext = 0;
while (!$endoftext)
{
$start = strpos($text, "");
$end = strpos($text, "");
if (($start) && ($end))
{
$url = substr($text, $start + 5, $end - $start - 5);
$newurl = "redirect.php?url=$url";
$oldurl = "" . $url . "";
$text = str_replace($oldurl, $newurl, $text);
}
else
{
$endoftext = 1;
}
}
return $text;
}