What are some potential pitfalls when using substr() function in PHP to extract characters from a string?

One potential pitfall when using the substr() function in PHP is that it may not behave as expected when dealing with multibyte characters, such as those in UTF-8 encoding. To correctly extract characters from a string while considering multibyte characters, you can use the mb_substr() function instead.

// Correctly extract characters from a string using mb_substr() function
$string = "Hello, 你好";
$substring = mb_substr($string, 0, 5, 'UTF-8');
echo $substring; // Output: Hello