What are some common encoding issues that can affect the output of PHP functions like substr() when dealing with special characters?
Common encoding issues that can affect the output of PHP functions like substr() when dealing with special characters include mismatched character encodings between the input string and the PHP environment, resulting in unexpected behavior or incorrect output. To solve this issue, it is important to ensure that the character encoding is consistent throughout the application.
// Set the character encoding to UTF-8
mb_internal_encoding('UTF-8');
// Use mb_substr() instead of substr() to handle multibyte characters properly
$input = "Café au lait";
$output = mb_substr($input, 0, 4);
echo $output; // Output: Café