massive words
| From: | Justin French | Date: | Sun, 02 Jun 2002 02:57:55 +0000 |
| Subject: | massive words | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-100272@lists.php.net to get a copy of this message | ||
hi all,
looking for some advice on the best way to approach this:
i have a guestbook running on a few sites, and occasionally we get
"creative" people who think it's a good idea to post messages with really
long words or URLs into the text, which totally mess up the layout of the
page.
what I need is an efficient way of checking the input for extremely long
words (say about 60-odd characters +)
I assume I just split the input by " " (space) into an array, and check that
each "word" isn't longer than 60 chars, but this seems like a lot of work
for the server... although I am limiting the entire input to 2000 chars, so
maybe this isn't too much work for the server?
this is what I'm using:
<?
$word_length = 5;
$error = 0;
$str = "cat dog bird mouse elephant"; // illegal
$str = explode(" ", $str);
foreach($str as $key => $word)
{
if(strlen($word) > $word_length)
{ $error = 1; }
}
if($error)
{ echo "sorry"; }
else
{
$str = implode(" ", $str);
echo $str."<BR>";
}
?>
any ways to improve it?
Justin