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:


it asumes thtat the word is: test ölakjdfölakjdöfkjaödlfkjöaksdjföl

Does anybody know why this happens?

Thanx for any help,


function max_word_length($string, $maxlength){
 $word = explode(" ",$string);
   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],
   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

Reply via email to