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);
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php