Re: strpos() suggestion
| From: | Rasmus Lerdorf | Date: | Wed, 13 Nov 2002 22:12:21 +0000 |
| Subject: | Re: strpos() suggestion | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-90986@lists.php.net to get a copy of this message | ||
The reason the functions are the way they are is because they directly
mirror the underlying C functions. strrpos() calls strrchr() directly.
But yes, some sort of new php_memnstr() based string searcher could
probably be written.
-Rasmus
On 13 Nov 2002, Monte Ohrt wrote:
> Hi,
>
> I had a little problem to solve today, and couldn't find any easy way to
> do it without some extra steps slicing things up.
>
> What I wanted to do is take an arbitrary point in a string, and find the
> position of the first '[' on the left of it, and the first ']' on the
> right of it.
>
> Finding the ']' was easy, I use strpos() to find the first occurance of
> ']' after my given point.
>
> Finding '[' however is not so easy. strrpos() was my first guess, but it
> does not work like strpos() at all. There is no optional third
> parameter, and on an unrelated note it only works with a single
> character, not a string. inconsistant ;-) My best solution was to slice
> the string at my point, then get the position of '[' with strrpos().
>
> I'm not sure of the most intuitive way to solve this. One way would be
> to add a feature to strpos(); if you supply a negative third parameter,
> it gives you the position of the first occurance to the _left_ of that
> point. I'm not sure if the number should represent the position from the
> end or beginning of the string. Another way, add a third parameter to
> strrpos() to start at a given point from the end of the string.
>
> I'd try submitting a patch, but I'm not sure of which way would be best,
> and my C is a bit rusty, I'd probably do more damage than help ;-)
>
> Thoughts?
> Monte
>
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php
>