Req #11457 [Com]: limit for str_replace()
| From: | ullisses at gmail dot com | Date: | Sat, 05 Apr 2014 11:06:13 +0000 |
| Subject: | Req #11457 [Com]: limit for str_replace() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185106@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=11457&edit=1
ID: 11457
Comment by: ullisses at gmail dot com
Reported by: adamw at uscho dot com
Summary: limit for str_replace()
Status: Wont fix
Type: Feature/Change Request
Package: *General Issues
PHP Version: 4.0.5
Block user comment: N
Private report: N
New Comment:
Are you kidding me? 13 years and "Won't fix"?
Simple code:
$bb_code =
array('[b]','[/b]','[i]','[/i]','[u]','[/u]');
$html_code =
array('<b>','</b>','<i>','</i>','<u>','</u>');
$html = str_replace($bb_code,$html_code,$edit);
Task:
Allow to use bbcode only 2 times in whole article.
Good luck with preg_replace.
I know it's possible, but when it comes to performance... yeah, right.
I'm too 'oldschool' to use "plugins" and "libraries" to replace
BBCode, and much too old to waste my servertime for preg_replace.
After years of crappy programming and wasting resources it's time to start doing it right - as
it was years ago.
So for God sake just add this simple limit, as you count replaces anyway...
Previous Comments:
------------------------------------------------------------------------
[2012-07-09 17:55:19] bfrohs at gmail dot com
Here's a workaround written in PHP that is 100% backward-compatible with str_replace: http://stackoverflow.com/a/11400172/526741
------------------------------------------------------------------------
[2011-04-27 08:30:16] cancausecancerr at yahoo dot com dot cn
I would vote to add a str_replaceonce function where the $count arg specifies which occurrence in
the string to change (negatives also.)
Changing the existing str_replace is something people can do on their own installation but I
don't think it will be changed in the main code because it could break some existing software
written in php.
------------------------------------------------------------------------
[2011-01-17 02:59:37] TrentTompkins at gmail dot com
This is such a great idea! I can't believe it was suggested 10 years ago and no one added it =/
------------------------------------------------------------------------
[2010-12-01 16:24:23] jani@php.net
Use preg_replace() if you need this.
------------------------------------------------------------------------
[2009-11-18 16:44:37] felipe dot tonello at felipetonello dot com
On version 5.3.0 the 4th parameter, count, does not work when not passed
by reference.
$count = 1;
echo str_replace("o", "a", "foo", $count); // returns "faa"
Even if it was working well, thought, this is not a good approach.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=11457
--
Edit this bug report at https://bugs.php.net/bug.php?id=11457&edit=1