note 111558 added to function.str-replace

From: Date: Mon, 04 Mar 2013 09:59:08 +0000
Subject: note 111558 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-193791@lists.php.net to get a copy of this message
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; ?> ---- Server IP: 69.147.83.199 Probable Submitter: 86.209.171.154 ---- Manual Page -- http://php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/111558 Del: integrated -- https://master.php.net/note/delete/111558/integrated Del: useless -- https://master.php.net/note/delete/111558/useless Del: bad code -- https://master.php.net/note/delete/111558/bad+code Del: spam -- https://master.php.net/note/delete/111558/spam Del: non-english -- https://master.php.net/note/delete/111558/non-english Del: in docs -- https://master.php.net/note/delete/111558/in+docs Del: other reasons-- https://master.php.net/note/delete/111558 Reject -- https://master.php.net/note/reject/111558 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193791) next »