What potential issues can arise when using substr() with multibyte characters in PHP?

When using substr() with multibyte characters in PHP, potential issues can arise due to the fact that substr() operates on bytes, not characters. This can lead to unintended results such as cutting off multibyte characters in the middle, resulting in broken or garbled text. To properly handle multibyte characters, you should use the mb_substr() function instead, which is specifically designed to work with multibyte characters.

// Using mb_substr() to handle multibyte characters
$text = "こんにちは世界"; // Japanese text with multibyte characters
$substring = mb_substr($text, 0, 5, 'UTF-8'); // Get the first 5 characters properly
echo $substring; // Output: こんにちは