Hi
I am having some problems with preg_replace and I wondering if someone could suggest a fix or explain why it is not working.
Here is the Code: ********************* <?php $code = "blah http://www.foo.com/Unsubscribe.php?EmailAddress=[MAIL] blah"; $url = "'http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]'"; echo "BEFORE : $code<br><br>"; $replace = "Foo"; $code = preg_replace($url,$replace,$code,1); echo "AFTER: $code<br>"; ?> **********************
Here is the results of the script:
**********************
BEFORE : blah http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah
AFTER: blah http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah
**********************
It should give the following result:
**********************
AFTER: blah Foo blah
**********************
$url = "/http:\/\/www.foo.com\/maxbid\/Unsubscribe.php?EmailAddress=\[MAIL\]/";
Will replace http://www.foo.com/Unsubscribe.php?EmailAddress=[MAIL] only. If you're looking to replace any URL, you need a regular expression. The first argument to preg_replace is the pattern you're looking for, so you need to enclose it in slashes ( /pattern/ ), and escape out any special characters.
-- By-Tor.com It's all about the Rush http://www.by-tor.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

