note 111558 deleted from function.str-replace by danbrown
| From: | danbrown@php.net | Date: | Mon, 04 Mar 2013 17:39:06 +0000 |
| Subject: | note 111558 deleted from function.str-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193796@lists.php.net to get a copy of this message | ||
Note Submitter: PRSTSC::DTL
----
If, like me, you code this:
<?php
$a="I do like %fruit%";
$b="%fruit%";
$c="apple";
echo "a= $a<br>";
str_replace($b,$c,$a);
echo "a= $a<br>";
exit;
?>
and then you spend one full hour to try to figure out why the second echo gives the same value as
the first one without the substitution, don't panic, the reason is obvious.
The str_replace fonction IS a function, not a subroutine. The result of the function should be put
into a variable.
So, the right coding was of course:
<?php
$a="I do like %fruit%";
$b="%fruit%";
$c="apple";
echo "a= $a<br>";
a$=str_replace($b,$c,$a);
echo "a= $a<br>";
exit;
?>