$text= '123 тутсловодлиннее10символов 123' 

How to analyze this text and cut out words longer than 10 characters? ... Help, please.

    3 answers 3

     $text= '123 тутсловодлиннее10символов 123'; $words = explode(" ", $text); foreach ($words as $key => $value) { $words[$key] = substr($value,0,10); } $text = implode(" ", $words); 

    Just tested for Cyrillic works incorrectly. Need to use mb_substr

    Those. get the code:

     $text= '123 тутсловодлиннее10символов 123'; $words = explode(" ", $text); foreach ($words as $key => $value) { $words[$key] = mb_substr($value,0,10,'utf8'); } $text = implode(" ", $words); 
       $text = '123 тутсловодлиннее10символов 123'; echo preg_replace('/\S{10,}/', '', $text); 
         $text= '123 тутсловодлиннее10символов 123'; if(strlen($text > 10)){ $s = substr($text, 10) str_replace($s, '', $text); } else { echo 'в тексте меньше 10 символов'; 

        like this, though I didn’t write like that as it was asked, but I pushed, and then they go on to the manual to teach full-time

        • substr ($ text, 0.10); - here is an analog): < - Manitikyl
        • one
          Well, you know better than me the regular functions, clave in hand and code-code! I honestly haven’t written to php for a long time, so I forgot about such trifles already - johniek_comp
        • attempts failed - Manitikyl
        • what exactly? I gave you all the functions, and even the algorithm, check that there were more than 10 characters (strlen), take out 10 characters (substr), cut them out from the text (str_replace) - johniek_comp