I am experiencing some problem on UTF-8 Encoding. I have a CSV file and this is the content of it:
Quién tú - Tes, más , S03
Who you, More, SO2
I have extracted it one by one and I have this condition in my loop
if(mb_detect_encoding($exploded_value[$i], 'UTF-8', true))
{
echo $cleaned_data = utf8_encode($exploded_value[$i]);
}
else
{
echo $cleaned_data=$exploded_value[$i];
}
My cleaned data became like this:
Quién tú - Tes
más
S03
Who you
More
SO2
Character's like á, ç, ú gets decoded and when retrieved it gives the wrong output.
Text with Spanish character are being detected as UTF-8 encode character. So, it falls into utf8_encode($exploded_value[$i]). And when utf8_encode perform its process it got decoded.
Declaration of my meta content type is charset=UTF8
Anyone have encountered this issue. Can you share on how did you fix it? Please help. I have googled around and didn't find any luck.
Your logic is reversed: you are re-encoding what is already utf-8 encoded, and what is not you pass on as-is.
To fix this just switch the if
and else
bodies:
if(mb_detect_encoding($exploded_value[$i], 'UTF-8', true))
{
// already UTF-8
echo $cleaned_data=$exploded_value[$i];
}
else
{
// not yet UTF-8
echo $cleaned_data = utf8_encode($exploded_value[$i]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.