$text= '123 тутсловодлиннее10символов 123' How to analyze this text and cut out words longer than 10 characters? ... Help, please.
$text= '123 тутсловодлиннее10символов 123' How to analyze this text and cut out words longer than 10 characters? ... Help, please.
$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
Source: https://ru.stackoverflow.com/questions/89284/
All Articles