str_replace() with count of replacements
| 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])
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2003-04-13 18:46 UTC] magnus@php.net