note 115946 added to function.str-replace
| From: | karst at onlinq dot nl | Date: | Fri, 17 Oct 2014 13:57:06 +0000 |
| Subject: | note 115946 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200673@lists.php.net to get a copy of this message | ||
"If search is an array and replace is a string, then this replacement string is used for every
value of search. The converse would not make sense, though. "
I think one important (and not at all vaguely theoretical) use-case is completely ignored here.
Take, for example, the way the PDO handles parameter replacement.
If we have the following query:
"SELECT * FROM my_table WHERE (id = ? AND my_column = ? AND other_column = ?);"
The "?"s should be replaced by each successive variable in a $parameters array. That is
EXACTLY the use case for "search" being a value and "replace" being an array.
Considering that this is not only a real-world example but also part of a core PHP functionality I
find it very strange that it's dismissed so easily here.
----
Server IP: 72.52.91.14
Probable Submitter: 88.159.23.235
----
Manual Page -- http://php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/115946
Del: integrated -- https://master.php.net/note/delete/115946/integrated
Del: useless -- https://master.php.net/note/delete/115946/useless
Del: bad code -- https://master.php.net/note/delete/115946/bad+code
Del: spam -- https://master.php.net/note/delete/115946/spam
Del: non-english -- https://master.php.net/note/delete/115946/non-english
Del: in docs -- https://master.php.net/note/delete/115946/in+docs
Del: other reasons-- https://master.php.net/note/delete/115946
Reject -- https://master.php.net/note/reject/115946
Search -- https://master.php.net/manage/user-notes.php