Closed GoogleCodeExporter closed 9 years ago
Do you know what the $encoding variable is getting set to? If the encoding is
unknown
then perhaps it should just return the original string at that point.
Original comment by step...@wettone.com
on 26 Jan 2010 at 8:49
Like this:
function utf8_encode( $_str ) {
$encoding = mb_detect_encoding( $_str );
if ( $encoding == false || strtoupper( $encoding ) == 'UTF-8' ) {
return $_str;
} else {
return iconv( $encoding, 'UTF-8', $_str );
}
}
Original comment by step...@wettone.com
on 26 Jan 2010 at 9:12
$encoding is set to ASCII
Original comment by dfens...@gmail.com
on 27 Jan 2010 at 9:16
In which case we can return at that point, because ASCII is a subset of UTF-8.
Give this a try:
function utf8_encode( $_str ) {
$encoding = mb_detect_encoding( $_str );
if ( $encoding == false || strtoupper( $encoding ) == 'UTF-8' || strtoupper(
$encoding ) == 'ASCII' ) {
return $_str;
} else {
return iconv( $encoding, 'UTF-8', $_str );
}
}
Original comment by step...@wettone.com
on 27 Jan 2010 at 9:20
Yup that seems to work. (Lacking test cases though so I'm not sure if it covers
it)
Original comment by dfens...@gmail.com
on 27 Jan 2010 at 11:08
This issue was closed by revision r83.
Original comment by step...@wettone.com
on 28 Jan 2010 at 3:31
Original issue reported on code.google.com by
dfens...@gmail.com
on 26 Jan 2010 at 6:20