Re: PHP Tokenize a String by its length
- From: Lüpher Cypher <lupher.cypher@xxxxxxxxxxx>
- Date: Sat, 31 Dec 2005 14:34:33 GMT
Geoff Berrow wrote:
Message-ID: <sSttf.3225$gq4.1485@trndny04> from Lüpher Cypher contained the following:
Actually, it's needed :)
Suppose $string = "aaa bbb ccc" and $length = 9, then:
first substr leaves "aaa bbb "
if we don't have the second trim, strrpos returns 8 and second substr returns "aaa bbb " so, "aaa bbb ..." will be returned instead of "aaa bbb..." :)
Think again.
strrpos returns 7
;-)
Actually:
$str = "aaa bbb ccc"; $str = substr($str,0,9); echo strrpos($str," ");
Outputs 8 :) There is a mistake, though:
instead of $str = substr($str,0,strrpos(trim($str)," ")); it should be $str1 = trim(substr($str,0,strrpos($str," ")));
Otherwise if it's trimmed first, it'll become "aaa bbb" and strrpos will return 3, resulting in "aaa" :)
luph .
- Follow-Ups:
- Re: PHP Tokenize a String by its length
- From: Geoff Berrow
- Re: PHP Tokenize a String by its length
- References:
- PHP Tokenize a String by its length
- From: Mavenos
- Re: PHP Tokenize a String by its length
- From: Geoff Berrow
- Re: PHP Tokenize a String by its length
- From: Lüpher Cypher
- Re: PHP Tokenize a String by its length
- From: Geoff Berrow
- Re: PHP Tokenize a String by its length
- From: Lüpher Cypher
- Re: PHP Tokenize a String by its length
- From: Geoff Berrow
- PHP Tokenize a String by its length
- Prev by Date: Re: Newbie - Redirect to do processing
- Next by Date: Re: Newbie - Redirect to do processing
- Previous by thread: Re: PHP Tokenize a String by its length
- Next by thread: Re: PHP Tokenize a String by its length
- Index(es):
Relevant Pages
|