The problem is that there are still special chars that need escaping. Specifically, the question mark (?) and the square braces ([]).
Here is some modified code (apologies for poor word-wrapping):
<?php $code = "blah http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah "; $url = "'http://www.foo.com/maxbid/Unsubscribe.php\?EmailAddress=\[MAIL\]'"; echo "BEFORE : $code\n\n"; $replace = "Foo"; $code = preg_replace($url,$replace,$code,1); echo "AFTER: $code\n"; ?>
When I run this, the output is:
BEFORE : blah http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah
AFTER: blah Foo blah
Next time, I'll test out my answers before I give 'em.
In $url, the periods still need to be escaped, too. This is where preg_quote() comes in handy.
$url = "http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]"; $url = preg_quote($url);
$code = preg_replace("#$url#",$replace,$code,1);
I hope the OP took notice of the str_replace() remark, too. :)
-- ---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php