使用utf8_decode解码一些特殊字符失败

时间:2015-05-13 11:20:09

标签: php decode

我正在尝试从Excel导入数据,当单元格有一些特殊字符时,utf8_decode函数失败。具体如下:

特别斜线:l'Olleria 特殊双斜线:“字”

如何解码这些字符?

Original data -> “camión”  c’amión
$data = $objWorksheet->getCellByColumnAndRow ( 0, $row )->getValue();
print -> “camión† w’ordb
$cleanedData = iconv('UTF-8', 'ASCII//TRANSLIT', $data);
print ->"cami?n"  c'ami?n

2 个答案:

答案 0 :(得分:0)

使用常规引号('和")替换Microsoft Word / Excel版本的单引号和双引号(""'')

iconv('UTF-8', 'ASCII//TRANSLIT', $some_string);

答案 1 :(得分:0)

我认为你需要这样的东西:

$asciiEncoded = iconv('UTF-8', 'ASCII//TRANSLIT', $utf8String);
$utf8Decoded = utf8_decode($utf8String);
$newString = '';

for ($i = 0; $i < strlen($utf8Decoded); $i++) {
    $newString .= substr($utf8Decoded, $i, 1) == '?' ? substr($asciiEncoded, $i, 1) : substr($utf8Decoded, $i, 1);
}