note 78201 deleted from function.str-replace by felipe
| From: | felipe@php.net | Date: | Sun, 06 Jan 2008 12:45:44 +0000 |
| Subject: | note 78201 deleted from function.str-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134867@lists.php.net to get a copy of this message | ||
Note Submitter: php at azulmx dot com
----
If your replace string results from an expression or a function, str_replace will evaluate/call it
even if the search string is not found.
function am_i_called ()
{
echo "oh no, i am<br>";
return "";
}
str_replace ("zzz", am_i_called (), "this string does not contain the search
string");
str_replace ("zzz", $result = "rats!", "this string does not contain the
search string");
echo "$result<br>";
// oh no, i am
// rats!
also it isn't re-evaluated for multiple replacements...
echo str_replace ("zzz", $result = "r".$result, "zzz zzz zzz zzz zzz zzz
zzz");
// rrats! rrats! rrats! rrats! rrats! rrats! rrats!