Here is simple code
Never use constant in substr
function for UTF-8
string:
$st = substr($text, $beg, 100);
50% chance you will get half of a character at end of the string.
Do it like this:
$postion_degin = strpos($text, $first_symbol);
$postion_end = strpos($text, $last_symbol);
$len = $postion_end - $postion_degin + 1;
$st = substr($text, $postion_degin, $len);
100% safe result.
No mb_substr
.