note 71682 added to function.str-replace

From: Date: Mon, 11 Dec 2006 20:09:44 +0000
Subject: note 71682 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-120515@lists.php.net to get a copy of this message
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. ---- Server IP: 216.194.113.175 Probable Submitter: 68.97.24.55 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/71682 Del: integrated -- https://master.php.net/note/delete/71682/integrated Del: useless -- https://master.php.net/note/delete/71682/useless Del: bad code -- https://master.php.net/note/delete/71682/bad+code Del: spam -- https://master.php.net/note/delete/71682/spam Del: non-english -- https://master.php.net/note/delete/71682/non-english Del: in docs -- https://master.php.net/note/delete/71682/in+docs Del: other reasons-- https://master.php.net/note/delete/71682 Reject -- https://master.php.net/note/reject/71682 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120515) next »