Forum Moderators: coopster

Message Too Old, No Replies

substr() and complet words

no chopping etc

         

ukgimp

4:03 pm on Jul 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the situation

$rest = substr("abcdef ghij klmn", 0, 4); // returns "abcd"

$rest = substr("abcdef ghij klmn", 0, 9); // returns "abcdef gh"

but how can you get it to look for the complete word or white space
so it returns

abcdef ghij

Can that be done without a monster bit of code

Cheers

Philosopher

4:14 pm on Jul 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could you use strtok() or explode() instead and use a space as the delimiter? That would give you your complete words, then it's just a matter of grabbing the words you are wanting.

coopster

6:03 pm on Jul 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have a look at Birdman's message in the thread regarding How to avoid words being chopped with SUBSTR [webmasterworld.com].

ukgimp

9:24 am on Jul 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



stunning, thanks :)