What best practices should be followed when concatenating or replacing strings with mixed character encodings in PHP to avoid unexpected results?

When concatenating or replacing strings with mixed character encodings in PHP, it is important to ensure that all strings are in the same encoding to avoid unexpected results. One way to do this is by using the `mb_convert_encoding()` function to convert all strings to a common encoding before concatenating or replacing them.

$string1 = "Hello, ";
$string2 = "世界";
$commonEncoding = 'UTF-8';

// Convert strings to a common encoding
$string1 = mb_convert_encoding($string1, $commonEncoding);
$string2 = mb_convert_encoding($string2, $commonEncoding);

// Concatenate the strings
$concatenatedString = $string1 . $string2;

echo $concatenatedString;