counting max word length fails on line brake

From: Date: Wed, 15 May 2002 10:49:30 +0000
Subject: counting max word length fails on line brake
Groups: php.general 
Request: Send a blank email to php-general+get-97688@lists.php.net to get a copy of this message
Hi there, I would like to check user input for to long words. Therefore I did code a function returning a string seperated by dash if it is more than $maxlength. If it is 2 times maxlength it returns false. Works good execept on line brakes. So if the input is: test ölakjdfölakjdöfkjaödlfkjöaksdjföl it asumes thtat the word is: test ölakjdfölakjdöfkjaödlfkjöaksdjföl Does anybody know why this happens? Thanx for any help, andy function max_word_length($string, $maxlength){ $word = explode(" ",$string); for($x=0;$x<count($word);$x++){ if (strlen($word[$x]) > 2 * $maxlength) return false; if (strlen($word[$x]) > $maxlength){ echo strlen($word[$x]).' '.$word[$x].'<br>'; $word[$x] = substr($word[$x],0, $maxlength).'-'.substr($word[$x], $maxlength); echo strlen($word[$x]).' '.$word[$x].'<br>'; } } return implode(" ", $word); }

« previous php.general (#97688) next »