Hey,
I'm proposing to add a new function str_replace_limit, this will be
identical to str_replace()
with one key difference, you can specify
how many times you want the replace to occur.
Currently this isn't possible with any functions in the
/ext/standard/string.c stack, the only easy workaround is using
preg_replace()
which requires of course the pcre library and regex
patterns.
I would have added this as a 4th param to str_replace()
, but it
already has a 4th by-ref param to tell you how many times it done the
replacement.
mixed str_replace_limit ( mixed $search , mixed $replace , mixed
$subject [, int $limit ] )
Thoughts?
Paul Dragoonis.
Hi,
2012/7/15 Paul Dragoonis dragoonis@gmail.com:
Hey,
I'm proposing to add a new function str_replace_limit, this will be
identical tostr_replace()
with one key difference, you can specify
how many times you want the replace to occur.Currently this isn't possible with any functions in the
/ext/standard/string.c stack, the only easy workaround is using
preg_replace()
which requires of course the pcre library and regex
patterns.I would have added this as a 4th param to
str_replace()
, but it
already has a 4th by-ref param to tell you how many times it done the
replacement.mixed str_replace_limit ( mixed $search , mixed $replace , mixed
$subject [, int $limit ] )Thoughts?
Surely a 5th param is preferred.
--
Regards,
Felipe Pena
The 4th param to str_replace is a by-ref param, so you can't just skip
over it, can you ?
Hi,
2012/7/15 Paul Dragoonis dragoonis@gmail.com:
Hey,
I'm proposing to add a new function str_replace_limit, this will be
identical tostr_replace()
with one key difference, you can specify
how many times you want the replace to occur.Currently this isn't possible with any functions in the
/ext/standard/string.c stack, the only easy workaround is using
preg_replace()
which requires of course the pcre library and regex
patterns.I would have added this as a 4th param to
str_replace()
, but it
already has a 4th by-ref param to tell you how many times it done the
replacement.mixed str_replace_limit ( mixed $search , mixed $replace , mixed
$subject [, int $limit ] )Thoughts?
Surely a 5th param is preferred.
--
Regards,
Felipe Pena
The 4th param to str_replace is a by-ref param, so you can't just
skip
over it, can you ?
I don't think so, but we could make it so that you could by using
optional passing by reference.
--
Gustavo Lopes
Hi all,
I'm a strict follower of this list and havent posted (as of yet) due to
the fact that i'd like to be in the loop, but am not a C developer... :)
But on this discussion i'd like to give my 2c: As a PHP developer i'd
regret to see yet another function added to the language instead of
adding a new parameter. (this it does the same thing just limited) Also
with the other discussion on being able to skip default parameters
(using the keyword 'default') this shouldnt be a problem should it?
Thanks, i'll butt out now :D
Op maandag 16 juli 2012 10:05:02, Gustavo Lopes schreef:
The 4th param to str_replace is a by-ref param, so you can't just skip
over it, can you ?I don't think so, but we could make it so that you could by using
optional passing by reference.
Thanks for the comments guys, I like your idea about skipping the
by-ref count parameter.
If the 'default' keyword were to be added in, then you could skip the
4th parameter and add your 5th 'limit' option.
$str = str_replace($search, $replace, $subject, default, 5);
Does anyone have any objections on this implementation approach?
(obviously we'd have to wait for the default param skipping to be
implemented, I'm not sure on the implementation status of that
feature)
Thanks.
Paul Dragoonis.
On Mon, Jul 16, 2012 at 9:08 AM, Kingsquare.nl - Robin Speekenbrink
robin@kingsquare.nl wrote:
Hi all,
I'm a strict follower of this list and havent posted (as of yet) due to the
fact that i'd like to be in the loop, but am not a C developer... :)But on this discussion i'd like to give my 2c: As a PHP developer i'd regret
to see yet another function added to the language instead of adding a new
parameter. (this it does the same thing just limited) Also with the other
discussion on being able to skip default parameters (using the keyword
'default') this shouldnt be a problem should it?Thanks, i'll butt out now :D
Op maandag 16 juli 2012 10:05:02, Gustavo Lopes schreef:
The 4th param to str_replace is a by-ref param, so you can't just skip
over it, can you ?I don't think so, but we could make it so that you could by using
optional passing by reference.
Thanks for the comments guys, I like your idea about skipping the
by-ref count parameter.If the 'default' keyword were to be added in, then you could skip the
4th parameter and add your 5th 'limit' option.$str = str_replace($search, $replace, $subject, default, 5);
Does anyone have any objections on this implementation approach?
(obviously we'd have to wait for the default param skipping to be
implemented, I'm not sure on the implementation status of that
feature)
I'm not seeing what's the problem with it being a by-ref variable, as
you've mentioned it twice now. Are you bothered by an additional
variable being set in memory when skipping (i.e. not using it)? Or am I
reading more into it than you tried to say? :)
Greetings,
Florian
On Mon, Jul 16, 2012 at 12:23 PM, Florian Anderiasch
florian@anderiasch.de wrote:
Thanks for the comments guys, I like your idea about skipping the
by-ref count parameter.If the 'default' keyword were to be added in, then you could skip the
4th parameter and add your 5th 'limit' option.$str = str_replace($search, $replace, $subject, default, 5);
Does anyone have any objections on this implementation approach?
(obviously we'd have to wait for the default param skipping to be
implemented, I'm not sure on the implementation status of that
feature)I'm not seeing what's the problem with it being a by-ref variable, as
you've mentioned it twice now. Are you bothered by an additional
variable being set in memory when skipping (i.e. not using it)? Or am I
reading more into it than you tried to say? :)
I believe you were reading more into it.
I mention by-ref so it's easy to know if i'm talking about the
existing or new proposed param.
I'm not bothered by the by-ref param being skipped over to get to the
5th one, it's a hit I'm willing to take to achieve necessary
functionality on str_replace()
.
If nobody has any further concerns I'll go ahead and create this new
parameter and provide a PR on github accordingly.
Paul Dragoonis.
Greetings,
Florian