What are some potential pitfalls to be aware of when working with character encoding in PHP?

One potential pitfall when working with character encoding in PHP is encountering issues with different character sets, which can lead to garbled or incorrect text display. To avoid this, it is important to consistently use the same character encoding throughout your application and properly handle any input or output data.

// Set the default character encoding to UTF-8
ini_set('default_charset', 'UTF-8');

// Use mb_internal_encoding to set the internal character encoding
mb_internal_encoding('UTF-8');

// Use mb_convert_encoding to convert strings to UTF-8
$utf8_string = mb_convert_encoding($input_string, 'UTF-8', 'auto');