php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Dante at altmuehlnet dot de
New email:
PHP Version: OS:

 

 [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])


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-13 18:46 UTC] magnus@php.net
Fixed by Pollita in PHP5 at least.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC