Req #38685 [Com]: ER: Allow str_replace with string subject, array replace
| From: | valentiny510 at yahoo dot es | Date: | Sun, 17 Mar 2013 03:57:58 +0000 |
| Subject: | Req #38685 [Com]: ER: Allow str_replace with string subject, array replace | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-177842@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=38685&edit=1
ID: 38685
Comment by: valentiny510 at yahoo dot es
Reported by: paulschreiber at gmail dot com
Summary: ER: Allow str_replace with string subject, array
replace
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: any
PHP Version: 4.4.4
Block user comment: N
Private report: N
New Comment:
For Paul: The syntax is incorrect.
For PHP Team: 7 years and is still open ???
Previous Comments:
------------------------------------------------------------------------
[2006-09-01 22:46:52] paulschreiber at gmail dot com
Description:
------------
The PHP docs for str_replace say:
"If search and replace are arrays, then str_replace() takes a value from each array and uses
them to do search and replace on subject. If replace has fewer values than search, then an empty
string is used for the rest of replacement values. 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 the converse makes sense in some cases. Here is an example:
$result = str_replace("?", array("Joe", "Smith"), "SELECT * FROM
people WHERE first = ? AND last = ?");
(Yes, if you were doing real database work, you'd need to escape everything.)
It would be nice if PHP supported this.
Reproduce code:
---------------
$result = str_replace("?", array("'Joe'",
"'Smith'"), "SELECT * FROM people WHERE first = ? AND last = ?");
print $result;
Expected result:
----------------
SELECT * FROM people WHERE first = 'Joe' AND last = 'Smith'
Actual result:
--------------
PHP Notice: Array to string conversion in /Users/paul/- on line 2
Notice: Array to string conversion in /Users/paul/- on line 2
SELECT * FROM people WHERE first = Array AND last = Array
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=38685&edit=1