Re: massive words

From: Date: Sun, 02 Jun 2002 03:46:35 +0000
Subject: Re: massive words
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-100278@lists.php.net to get a copy of this message
Thanks! Justin on 02/06/02 1:18 PM, Bogdan Stancescu (mgv@fx.ro) wrote: > First, you don't need to explode and then implode - just use a different > var for the exploded array and use the original after the test. > > My suggestion for testing (but you really must test it and see if it's > faster or slower than your method) is using wordwrap() with your max > word length and then check if any line is longer than your max allowed > length. The advantage may be that you probably use 10-15 as the max > length in real life and you would skip quite a few checks because you're > going to end up with several words on a typical line. I guess it *might* > be slightly fatser because wordwrap() is native to PHP - the job however > is more complicated, so you may end up with a slower version than your > current one. > > Bogdan > > Justin French wrote: > >> 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 >> >> >> >> > > >

« previous php.general (#100278) next »