[PHP] Split haystack at nth occurrence of needle?

2004-09-22 Thread Brian Dunning
I've been RTFMing for about an hour and I can't find a string function to split haystack 'onebrtwobrthreebrfourbrfive' at the nth occurrence of needle 'br'. strpos gives me the position of the first needle, and strrpos gives me the position of the last needle. But I'm looking for the position

Re: [PHP] Split haystack at nth occurrence of needle?

2004-09-22 Thread Chris Boget
I've been RTFMing for about an hour and I can't find a string function to split haystack 'onebrtwobrthreebrfourbrfive' at the nth occurrence of needle 'br'. strpos gives me the position of the first needle, and strrpos gives me the position of the last needle. But I'm looking for the

Re: [PHP] Split haystack at nth occurrence of needle?

2004-09-22 Thread Brian Dunning
? $string = 'onebrtwobrthreebrfourbrfive'; $nthPos = 4; $tmpArr = explode( 'br', $string ); $nthString = $tmpArr[($nthPos - 1)]; ? Thanks Chris, that works great, but it's not doing what I want. I'm just trying to get the position of the 3rd occurrence (for example) of 'br'. So I'm

Re: [PHP] Split haystack at nth occurrence of needle?

2004-09-22 Thread Silvio Porcellana
'three') all you have to do is: $out[1][1][1] = 14 Just my .2 euros... Silvio Porcellana - Original Message - From: Brian Dunning [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 22, 2004 5:54 PM Subject: [PHP] Split haystack at nth occurrence of needle? I've been RTFMing

Re: [PHP] Split haystack at nth occurrence of needle?

2004-09-22 Thread Robert Cummings
On Wed, 2004-09-22 at 12:31, Brian Dunning wrote: ? $string = 'onebrtwobrthreebrfourbrfive'; $nthPos = 4; $tmpArr = explode( 'br', $string ); $nthString = $tmpArr[($nthPos - 1)]; ? Thanks Chris, that works great, but it's not doing what I want. I'm just trying to get the

Re: [PHP] Split haystack at nth occurrence of needle?

2004-09-22 Thread Janet Valade
Brian Dunning wrote: Thanks Chris, that works great, but it's not doing what I want. I'm just trying to get the position of the 3rd occurrence (for example) of 'br'. So I'm looking for a function that will return the value 19, given the above example string. From your first post, you just want

Re: [PHP] Split haystack at nth occurrence of needle?

2004-09-22 Thread Brian Dunning
I don't understand why explode won't work for you. The explode solution is working. Thanks very much to everyone who replied with so much great information! - Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Split haystack at nth occurrence of needle?

2004-09-22 Thread Curt Zirzow
* Thus wrote Janet Valade: Brian Dunning wrote: Thanks Chris, that works great, but it's not doing what I want. I'm just trying to get the position of the 3rd occurrence (for example) of 'br'. So I'm looking for a function that will return the value 19, given the above example string.

Re: [PHP] Split haystack at nth occurrence of needle?

2004-09-22 Thread Curt Zirzow
* Thus wrote Curt Zirzow: $shortString = implode('br', explode('br', $string, $nth)); ignore this. Curt -- The above comments may offend you. flame at will. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php