|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #8218 str_replace() with count of replacements
Submitted: 2000-12-12 21:45 UTC Modified: 2003-04-13 18:46 UTC
From: Dante at altmuehlnet dot de Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.3pl1 OS: Any
Private report: No CVE-ID: None
 [2000-12-12 21:45 UTC] Dante at altmuehlnet dot de
What about an optional argument to str_replace which contains the count of replacements...
For example:
$text = "Foobar [b]abc[/b] def [b]ghi";
$tmp_text = str_replace("[b]", "<b>", $text, &$replace_count_open);
$new_text = str_replace("[/b]", "</b>", $text, &$replace_count_close);

if($replace_count_open > $replace_count_close)
    $new_text .= str_repeat("</b>", $replace_count_open - $replace_count_close);

The original definition:
string str_replace (string needle, string str, string haystack)
The definition with this feature:
string str_replace (string needle, string str, string haystack [, int count])


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-13 18:46 UTC]
Fixed by Pollita in PHP5 at least.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Oct 05 09:05:52 2022 UTC