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
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
?
$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
'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
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
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
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
* 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.
* 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
9 matches
Mail list logo