|
Posted by Lόpher Cypher on 12/31/05 13:23
Geoff Berrow wrote:
> Message-ID: <HWstf.630$i%4.305@trndny08> from LΓΌpher Cypher contained
> the following:
>
>> Shorter :)
>>
>> function trancate($string,$length) {
>> $string = substr(trim($string),0,$length);
>> $string = substr($string,0,strrpos(trim($string)," "));
>> return "$string...";
>> }
>
> You don't need the last trim()
>
> $string = substr($string,0,strrpos($string," "));
>
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..." :)
luph
[Back to original message]
|