Reply to Re: PHP Tokenize a String by its length

Your name:

Reply:


Posted by Lόpher Cypher on 12/31/05 16:34

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

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация