Prevent doubly encoding UTF-8 content when incoming data could be UTF-8, ASCII or another character set
$recTitle = $record['title']; | |
$encoding = mb_detect_encoding( $recTitle, 'UTF-8', true ); | |
if ( empty( $encoding ) ) { | |
$recTitle = mb_convert_encoding( $recTitle, 'UTF-8' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
The third parameter of mb_detect_encoding is our trick. Strict specifies whether to use the strict encoding detection or not. By default, it's false hence the trouble when using only
mb_detect_encoding( $recTitle, 'UTF-8' );
.http://php.net/manual/en/function.mb-detect-encoding.php
http://www.php.net/manual/en/function.mb-convert-encoding.php