What are the potential pitfalls of not accurately representing Unicode characters in PHP and how can they be avoided?

Not accurately representing Unicode characters in PHP can lead to issues with displaying, processing, and manipulating multilingual text. To avoid these pitfalls, it is important to use the appropriate functions and settings in PHP to handle Unicode characters properly.

// Set the internal encoding to UTF-8
mb_internal_encoding('UTF-8');

// Use mb functions for string operations
$unicodeString = 'Привет, 世界';
$length = mb_strlen($unicodeString);
$subString = mb_substr($unicodeString, 0, 5);

echo $length . "\n"; // Output: 11
echo $subString; // Output: Привет