Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-20 Thread Larry Garfield
On 12/19/12 10:30 PM, Christopher Jones wrote: On 12/19/2012 03:18 PM, Larry Garfield wrote: You could likely simplify the code even further using an infinite iterator: http://us1.php.net/infiniteiterator $result = preg_replace_callback( '/word/', function($matches) use

Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-20 Thread Christopher Jones
On 12/20/2012 08:31 AM, Larry Garfield wrote: On 12/19/12 10:30 PM, Christopher Jones wrote: On 12/19/2012 03:18 PM, Larry Garfield wrote: You could likely simplify the code even further using an infinite iterator: http://us1.php.net/infiniteiterator $result = preg_replace_callback(

Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-20 Thread David Muir
On 21/12/12 10:34, Christopher Jones wrote: On 12/20/2012 08:31 AM, Larry Garfield wrote: On 12/19/12 10:30 PM, Christopher Jones wrote: On 12/19/2012 03:18 PM, Larry Garfield wrote: You could likely simplify the code even further using an infinite iterator:

Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-20 Thread Christopher Jones
On 12/20/2012 04:05 PM, David Muir wrote: The curiosity (bug?) is the need to call rewind(): $replacements_iterator = new InfiniteIterator(new ArrayIterator($replacements)); $replacements_iterator-rewind(); // why is the rewind needed? $result = preg_replace_callback( '/word/',

Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-19 Thread Andrey Andreev
I've personally requested this on the bug tracker: https://bugs.php.net/bug.php?id=62315 P.S.: I hope this gets properly tracked to the thread as I read it from the archive and am not subscribed to the list. - Andrey -- PHP Internals - PHP Runtime Development Mailing List To

Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-19 Thread Larry Garfield
On 12/18/12 7:44 AM, Leigh wrote: On 18 December 2012 13:24, Stefan Neufeind neufe...@php.net wrote: Since we already have functionality for replacing with arrays in place, I wondered if giving it one string to replace and then an array to choose the replacement from (rotating) would be an

Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-19 Thread Christopher Jones
On 12/19/2012 03:18 PM, Larry Garfield wrote: You could likely simplify the code even further using an infinite iterator: http://us1.php.net/infiniteiterator $result = preg_replace_callback( '/word/', function($matches) use ($replacements_iterator) { return

[PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-18 Thread Stefan Neufeind
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

Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-18 Thread Leigh
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

Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-18 Thread Stefan Neufeind
Hi, On 12/18/2012 01:16 PM, Leigh wrote: 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. Well, yes and no. Currently you have to supply either one string to replace with

Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-18 Thread Leigh
On 18 December 2012 13:24, Stefan Neufeind neufe...@php.net wrote: Since we already have functionality for replacing with arrays in place, I wondered if giving it one string to replace and then an array to choose the replacement from (rotating) would be an option. Currently that's unsupported