Page 1 of 1

Limit Word Size in String

Posted: Fri Dec 09, 2011 7:38 pm
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}

Re: Limit Word Size in String

Posted: Fri Dec 09, 2011 9:01 pm
by Celauran
Explode on space and loop through the resulting array?

Re: Limit Word Size in String

Posted: Fri Dec 09, 2011 11:17 pm
by Hermit TL
Thank you; I have it working nicely now.