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

Reply via email to