There are many ways to do it, but everything requires a manipulation to the string. strrev() would not only require the entire string to be swapped around, but you'd also have to recompute the string position to count from. The best way as it stands (that I see) is to slice the array then use strrpos(), as stated below. But I'm suggesting a feature to be able to do this kind of calculation the quickest, ie. no extra vars to create, no manipulation to the string required.
On Wed, 2002-11-13 at 16:24, Mike Hall wrote: > Why couldn't you just strrev() the string and then strpos() for it? > > Mike > > ----------------------- Original Message ----------------------- > From: Monte Ohrt <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Date: 13 Nov 2002 16:02:54 -0600 > Subject: [PHP-DEV] strpos() suggestion > > 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 -- Monte Ohrt <[EMAIL PROTECTED]> -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php