note 4243 deleted from ref.strings by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 15 Sep 2004 20:49:45 +0000 |
| Subject: | note 4243 deleted from ref.strings by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76800@lists.php.net to get a copy of this message | ||
Note Submitter: heiko at individual-web dot com
----
[Editor's note: Alternativaly, wordwrap() function is available for this purpose]
I had the problem that in some of the guestbooks I programmed, people entererd trash like 400
characters without spaces and such. Without any spaces there was no way to break the lines and the
whole guestbooked looked screwed. I wrote this little function that makes sure no words are more
than a specified number of characters long. If a word is too long, spaces are inserted to get the
word to the maximum length allowed. Maybe it's useful to some of you:
<?php
function strmaxwordlen($input,$len) {
$l = 0;
$output = "";
for ($i = 0; $i < strlen($input); $i++) {
$char = substr($input,$i,1);
if ($char != " ") { $l++; } else { $l = 0; }
if ($l == $len) { $l = 0; $output .= " "; }
$output .= $char;
}
return($output);
}
?>