What are some potential issues with using substr() in PHP for string manipulation?

One potential issue with using substr() in PHP for string manipulation is that it may not handle multibyte characters correctly, leading to unexpected results when working with languages like Chinese or Japanese. To solve this issue, you can use the mb_substr() function instead, which is specifically designed to handle multibyte characters.

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