note 26246 deleted from ref.strings by aidan
| From: | aidan@php.net | Date: | Tue, 28 Sep 2004 12:12:14 +0000 |
| Subject: | note 26246 deleted from ref.strings by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77495@lists.php.net to get a copy of this message | ||
Note Submitter: discord at mac dot com
----
If you are outputting to html, it might be better to insert a wordbreak (<wbr>) tag to allow a
linebreak. If the text is too long and needs to be wrapped, the browser will break the line at that
tag, otherwise, it ignores it. This is good because it won't even show up as a space if the
browser doesn't wrap it at that point.
Here's an optimised preg_replace version of the strmaxwordlen function that uses this tag:
function splitLongWords($text, $max) {
return preg_replace( '/([^\s]{'.$max.'})(?=[^\s])/',
'$1<wbr>', $text);
}
(note: I didn't test this thoroughly, it may need some work :)