note 71682 deleted from function.str-replace by philip

From: Date: Mon, 26 Feb 2007 07:04:00 +0000
Subject: note 71682 deleted from function.str-replace by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123886@lists.php.net to get a copy of this message
Note Submitter: Jon Baker ---- If you need to do a replace that may contain a dollar sign, preg_replace will parse the replacement string as PHP and expand the dollar sign as a variable. I.e.: <?php $content = "This product is valued at $12.95"; $html = preg_replace("/%content%/", $content, $html); ?> will return "This product is valued at .95" which is probably not what you need. Instead, if you can, use str_replace(): <?php $content = "This product is valued at $12.95"; $html = str_replace("%content%", $content, $html); ?> which will return "This product is valued at $12.95" as expected. Of course, if you need the regular expression then obviously this won't work.

« previous php.notes (#123886) next »