Doc #77994 [Nab]: Missing Detail in str_replace Documentation
| From: | requinix@php.net | Date: | Thu, 09 May 2019 06:33:30 +0000 |
| Subject: | Doc #77994 [Nab]: Missing Detail in str_replace Documentation | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-16637@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77994&edit=1
ID: 77994
Updated by: requinix@php.net
Reported by: mark at manngo dot net
Summary: Missing Detail in str_replace Documentation
Status: Not a bug
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I suppose? It's an unusual usage of the function. In fact I'd bet that most of the time
someone uses str_replace with arrays (strtr is easier) and the two arrays aren't the same size,
it's a bug - or at least unintentional.
If you have a use case in mind, you can hit the Edit link in the top-right corner and submit a patch
including an example. (Or amend the existing "gotchas" example.) The docs are written in
XML but there should be enough there to understand how it works.
Previous Comments:
------------------------------------------------------------------------
[2019-05-09 06:25:29] mark at manngo dot net
Gad, youâre right. Sorry, I missed that.
It might help to include an example, though.
------------------------------------------------------------------------
[2019-05-09 06:18:14] requinix@php.net
Sure it does.
> If replace has fewer values than search, then an empty string is used for the rest of
> replacement values.
------------------------------------------------------------------------
[2019-05-09 06:13:09] mark at manngo dot net
Description:
------------
---
From manual page: https://php.net/function.str-replace
---
The document makes no mention of what happens if the replace array is smaller than the search array.
It appears that the search characters will be replaced with an empty string. This may or may not be
expected, as the alternative result might have been to ignore the characters.
Test script:
---------------
$string='apple banana cherry apple banana cherry apple banana cherry';
$search=['apple','banana'];
$replace=['accordion','banjo'];
print str_replace($search,$replace,$string);
print "\n";
$replace=['accordion'];
print str_replace($search,$replace,$string);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77994&edit=1