Re: Adding a more logical string slicing function to PHP

From: Date: Wed, 30 Mar 2011 14:08:56 +0000
Subject: Re: Adding a more logical string slicing function to PHP
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-51750@lists.php.net to get a copy of this message
On 30 March 2011 15:05, Hannes Landeholm <landeholm@gmail.com> wrote: > Parsing is a problem in many real-world > problems and substr currently works great for that purpose. That's funny because the first thing I thought when I read the original mail was "oh that would be great for parsing." In fact, I've just grep'ed through some code from a rich text parser I've been working on and at first glance there are at ~5 occurences of substr() that I would replace with str_slice(). There are also 15+ occurences of substr() that would remain untouched. It's not black-and-white, sometimes you want N characters starting from pos X, and other times you want to cut the text from pos X and pos Y, and that's where str_slice() would be welcome. This thread shouldn't be a criticism of substr(), it would be pointless. Its signature and behaviour will never change, unless perhaps around April 1st as a practical joke on the millions of websites it would break. The question is: is str_slice() useful, does it fill a need and should it be included into PHP? -JD

« previous php.internals (#51750) next »