What potential issues should be considered when manipulating strings in PHP?
One potential issue when manipulating strings in PHP is the risk of encountering encoding problems, especially when dealing with multibyte characters. To handle this, it's important to use functions that support multibyte character encoding, such as mb_strlen() and mb_substr(). Additionally, be cautious when using functions like strlen() and substr() as they may not work as expected with multibyte characters.
// Example of using mb_strlen() and mb_substr() to handle multibyte characters
$string = "こんにちは"; // Japanese greeting
$length = mb_strlen($string);
$substring = mb_substr($string, 0, 3);
echo $length; // Output: 5
echo $substring; // Output: こん