Extract substring from a UTF-8 string in PHP

When you are working with UTF-8 encoded strings you may lose characters or get question marks when you are trying to extract a substring from them, using substr() function. As you already know this happens because UTF-8 characters have length between 1 and 4 bytes.  To deal with this problem we are going to use the mb_substr() function.

$value = "my_utf8_string";
$value = mb_substr($value, 0, 10, 'UTF-8');