What are potential challenges or limitations when using the substr() function in PHP to extract a substring from a string?

One potential challenge when using the substr() function in PHP is that it may not handle multibyte characters correctly, resulting in unexpected behavior or incorrect substring extraction. To solve this issue, you can use the mb_substr() function instead, which is specifically designed to work with multibyte characters.

// Using mb_substr() to extract a substring from a string with multibyte characters
$string = "こんにちは、世界!";
$substring = mb_substr($string, 0, 5, 'UTF-8');
echo $substring; // Output: こんにちは