note 105003 added to function.str-replace
| From: | dave dot haefliger at gmail dot com | Date: | Thu, 21 Jul 2011 17:59:16 +0000 |
| Subject: | note 105003 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181764@lists.php.net to get a copy of this message | ||
If you find yourself getting the following error when specifying the number of replacements to make,
the solution is all too simple.
Fatal error: Only variables can be passed by reference in [filename] on line [line]
The code that throws:
<?php
$replacedcontent = str_replace($search, $repleace, $subject, 1);
?>
The problem is the 4th parameter: as noted in the documentation str_replace is expecting it by
reference.
Simply change the code to:
<?php
$count = 1;
$replacedcontent = str_replace($search, $repleace, $subject, $count);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 67.162.100.104
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/105003
Del: integrated -- https://master.php.net/note/delete/105003/integrated
Del: useless -- https://master.php.net/note/delete/105003/useless
Del: bad code -- https://master.php.net/note/delete/105003/bad+code
Del: spam -- https://master.php.net/note/delete/105003/spam
Del: non-english -- https://master.php.net/note/delete/105003/non-english
Del: in docs -- https://master.php.net/note/delete/105003/in+docs
Del: other reasons-- https://master.php.net/note/delete/105003
Reject -- https://master.php.net/note/reject/105003
Search -- https://master.php.net/manage/user-notes.php