Both str_replace and preg_replace already support some array based
replacements, I think adding more options to these functions specifically
would just lead to confusion.

What you're proposing can already be achieved quite easily with
preg_replace_callback and passing your array/options into the anonymous
function with `use`, I'd personally welcome a str_replace_callback
counterpart.


On 18 December 2012 12:08, Stefan Neufeind <neufe...@php.net> wrote:

> Hi,
>
> inside a framework-/scripting-project we've lately discussed
> string-replacements with arrays.
>
> Currently PHP supports either replacing one string by another or
> replacing first element from one array with first from another array.
>
> What I'd like to propose is for str_replace and preg_replace to introduce:
> * a functionality to replace one string with strings from an array
> * to (optionally) allow for rolling replacements (1,2,3, 1,2,3, ...)
> * to (optionally) allow to skip strings already replaced
>   (that means not to accidentially double-replace strings)
>
> This would allow to do things like
>
> $content = str_replace('<li>',
>   array('<li class="A">', '<li class="B">', '<li class="C">'),
>   $content);
>
> optionally starting over from A again. (Current default is to stop when
> there are no more elements to replace with).
>
>
> Would such a change/extension find support?
>
>
> Kind regards,
>  Stefan Neufeind
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to