Limit Word Size in String

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hermit TL
Forum Commoner
Posts: 69
Joined: Mon Nov 21, 2011 12:16 am

Limit Word Size in String

Post by Hermit TL »

How can I check each word in a string of text for the length of each word and edit the string if a word is too long?
For example

$string = "supercalifragilisticexpialidocious of course if you say it backwards it would be Suoicodilaipxecitsiligarfilacrepus"
$string = no_long_words($string, 11); //($string, $maxlen)

echo $string; > {lenEx} of course if you say it backwards it would be {lenEx}
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Limit Word Size in String

Post by Celauran »

Explode on space and loop through the resulting array?
Hermit TL
Forum Commoner
Posts: 69
Joined: Mon Nov 21, 2011 12:16 am

Re: Limit Word Size in String

Post by Hermit TL »

Thank you; I have it working nicely now.
Post Reply