problem with ereg_replace
| From: | Elias Santiago | Date: | Wed, 15 Aug 2001 15:45:27 +0000 |
| Subject: | problem with ereg_replace | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-8878@lists.php.net to get a copy of this message | ||
I'm trying to replace all relative links in a string like:
str$="<a href="jan_may2000/files.html">" to
str$="<a href="http://myhost.com/jan_may2000/files.html">"
I don't want to change any links that begining with http or mailto links.
my code is:
<?
// change all relative links to include base url
$url = "news/";
$fnd = "a href=\"[^http)(mailto)#]";
$str_new = ereg_replace($fnd, "a href=\"" . $url . "", $str_old);
$news_body = $str_new;
?>
$str_old has the complete html body of the page (all content between <BODY>
tags), so none of the other html must be touched
It works, EXCEPT that $str_new returns what I want but strips the first
character after href. Using the example given above:
IF str$="<a href="jan_may2000/files.html">" after using the ereg
function
it becomes :
str$="<a href="http://myhost.com/an_may2000/files.html">"
^^ notice the missing
character.
What I'm doing wrong?