[VOTE] Feature request #38685: str_[i]replace(): Add support for (string needle, array replace)

php.internals

François Laupretre

11 years ago
Hi, Opening the vote for : https://wiki.php.net/rfc/cyclic-replace This RFC adds support in str_replace() and str_ireplace() for the combination of (string needle, array replace). In this case, each occurrence of the needle is replaced with an element of the 'replace' array. Cheers François

Andrey Andreev

11 years ago
Hi, On Mon, Feb 2, 2015 at 7:00 PM, François Laupretre <francois@tekwire.net> wrote:
> Hi, > > Opening the vote for : > > https://wiki.php.net/rfc/cyclic-replace > > This RFC adds support in str_replace() and str_ireplace() for the > combination of > (string needle, array replace). In this case, each occurrence of the needle > is replaced with an element of the 'replace' array. >
I seem to have missed the new parameter (and constants) addition during the discussion ... sorry to say this, but that one would probably fail the RFC. Cheers, Andrey.

François Laupretre

11 years ago
> De : Andrey Andreev [mailto:narf@devilix.net] > > I seem to have missed the new parameter (and constants) addition > during the discussion ... sorry to say this, but that one would > probably fail the RFC.
Mmh... I don't like the idea of adding a parameter but several people argued that we needed a way to control looping behavior, as the original idea was to loop through the replace array. But I am still hesitating. Instead of voting on the RFC, please tell me which behavior you prefer : - an options argument to decide on the looping behavior, - always stopping replacements when the replace array is exhausted - always looping The other options are too exotic to become the default behavior. Cheers François

Andrey Andreev

11 years ago
Hi, On Mon, Feb 2, 2015 at 7:58 PM, François Laupretre <francois@tekwire.net> wrote:
>> De : Andrey Andreev [mailto:narf@devilix.net] >> >> I seem to have missed the new parameter (and constants) addition >> during the discussion ... sorry to say this, but that one would >> probably fail the RFC. > > Mmh... I don't like the idea of adding a parameter but several people argued that we needed a way to control looping behavior, as the original idea was to loop through the replace array. > > But I am still hesitating. > > Instead of voting on the RFC, please tell me which behavior you prefer : > > - an options argument to decide on the looping behavior, > - always stopping replacements when the replace array is exhausted > - always looping > > The other options are too exotic to become the default behavior. >
Always looping, the other option is already covered by strtr(). I'd like control over the behavior too, but that just makes the API really ugly. Cheers, Andrey.

Andrey Andreev

11 years ago
On Feb 3, 2015 1:08 PM, "Andrey Andreev" <narf@devilix.net> wrote:
> > Hi, > > On Mon, Feb 2, 2015 at 7:58 PM, François Laupretre <francois@tekwire.net>
wrote:
> >> De : Andrey Andreev [mailto:narf@devilix.net] > >> > >> I seem to have missed the new parameter (and constants) addition > >> during the discussion ... sorry to say this, but that one would > >> probably fail the RFC. > > > > Mmh... I don't like the idea of adding a parameter but several people
argued that we needed a way to control looping behavior, as the original idea was to loop through the replace array.
> > > > But I am still hesitating. > > > > Instead of voting on the RFC, please tell me which behavior you prefer : > > > > - an options argument to decide on the looping behavior, > > - always stopping replacements when the replace array is exhausted > > - always looping > > > > The other options are too exotic to become the default behavior. > > > > Always looping, the other option is already covered by strtr(). > I'd like control over the behavior too, but that just makes the API
really ugly.
> > Cheers, > Andrey.
Or rather, should be covered by strtr(). Cheers, Andrey.

Leigh

11 years ago
I missed the discussion on this entirely. I see it took place in a non-obvious thread, in which Nikita asked: On 10 January 2015 at 11:53, Nikita Popov <nikita.ppv@gmail.com> wrote:

Leigh

11 years ago
On 2 February 2015 at 17:00, François Laupretre <francois@tekwire.net> wrote:
> Hi, > > Opening the vote for : > > https://wiki.php.net/rfc/cyclic-replace > > This RFC adds support in str_replace() and str_ireplace() for the > combination of > (string needle, array replace). In this case, each occurrence of the needle > is replaced with an element of the 'replace' array. > > Cheers > > François >
I think I would much prefer a str_replace_callback to compliment preg_replace_callback. This would make it trivial to implement a cyclic replacement or any other scheme you desire.

Yasuo Ohgaki

11 years ago
Hi Francois, On Tue, Feb 3, 2015 at 2:00 AM, François Laupretre <francois@tekwire.net> wrote:
> Opening the vote for : > > https://wiki.php.net/rfc/cyclic-replace > > This RFC adds support in str_replace() and str_ireplace() for the > combination of > (string needle, array replace). In this case, each occurrence of the needle > is replaced with an element of the 'replace' array. >
I guess you mean discussion? Example code would be nice for this RFC. Regards,
-- Yasuo Ohgaki yohgaki@ohgaki.net

François Laupretre

11 years ago
>De : yohgaki@gmail.com [mailto:yohgaki@gmail.com] De la part de Yasuo Ohgaki
>On Tue, Feb 3, 2015 at 2:00 AM, François Laupretre <francois@tekwire.net> wrote: >Opening the vote for :
> https://wiki.php.net/rfc/cyclic-replace
> I guess you mean discussion?
Actually, I wanted to open the vote, as discussion took place one month ago. But, as people seem to discover the RFC, yes, we're starting another discussion. Cheers François

Derick Rethans

11 years ago
On Mon, 2 Feb 2015, François Laupretre wrote:
> Opening the vote for : > > https://wiki.php.net/rfc/cyclic-replace
There doesn't seem to be a voting option? In any case, there are no code examples in that RFC. I think they really ought to be part of it. cheers, Derick