Is there any way 2 search thru a string for long words, say 60 chars and wrap them in the middle so that they won't ruin the web layout? Anybody who can help?
Hey, what language is this, with 60-letter words?
How about:
Explode the string into an array of words, using a space as the delimiter. $array = explode(" ",$string);
Check all the words in the array for length of 60 using "strlen".
If you find a long word, split it with an HTML "br" tag, using say: $array[$i]=substr($array[$i],0,30)."<br>".substr($array[$i],30)
Then join the array and echo it: echo join(" ",$array);
It's not a language, but the thing is...if it's possible 2 mess up a site by wrting long words so that the layout will be mess up, they WILL do it 😉
Thanx 4 the code example =)
Is there a way to do this without breaking up the string, perhaps with an ereg() statement? I'm not especially well-versed in regex's, but it seems like this might also be possible.
here's a perl style regex that'll take care of wrapping long words:
$alltext = preg_replace('/([\s<>]{60,60})/', '\1 ', $alltext);
note: the <> prevents it from messing with run-on html formatting.