Re: Adding a more logical string slicing function to PHP
| From: | Alban LEROUX | Date: | Fri, 01 Apr 2011 07:01:27 +0000 |
| Subject: | Re: Adding a more logical string slicing function to PHP | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51781@lists.php.net to get a copy of this message | ||
Hi all,
I just come back on the first reflexion about adding a str_slice() function. As it
says before, using one method or the orther can really sucks in some cases, depending
what you are coding about.
So actually you mention there is two possibility :
- Keep all in the actual state. substr is allready quite cool but can suck in some
case.
- Add a new function and a create a possible confusion about the two method name
(like javascript), etc... bad idea.
In fact I see a third possibility, change the substr() function to handle the both
case. Here a simple proto :
string substr( string $string, int $start [, int $second [, int $flag = SUBSTR_LENGTH ]])
with flags :
- SUBSTR_LENGTH (the default flags value corresponding to the actual behavior)
- SUBSTR_OFFSET (the new possibility to use an offset in third argument)
This keep the compatility with the actual substr() function, and enchance it, so
why not ?
On 2011-03-31 19:58:42 +0200, Martin Scotta said:
--20cf307d046c3ddbde049fcb0b8f Content-Type: text/plain; charset=ISO-8859-1 I think it's time to stop thinking in terms of "functions" and move forward to "abstractions" $s1 = 'string'; $s1->contains($s2); $s1->indexOf($s2) === strpos($s1, $s2); Why can't the strings be exposed as pseudo-objects ? users can choose to use them as a regular strings or by calling methods on it. Martin Scotta On Thu, Mar 31, 2011 at 12:52 PM, Rasmus Lerdorf <rasmus@lerdorf.com> wrote: On 03/31/2011 08:45 AM, Philip Olson wrote:-- Alban Leroux seza@paradoxal.org Web developper- Intuitive nameArgh! Everyone should be forced to learn a bit of C. Like many PHP functions, the name and argument order is right out of libc. If you type "man strstr" at your (non-Windows) prompt you get a nice little description of what it does. -Rasmus --20cf307d046c3ddbde049fcb0b8f--