【发布时间】:2015-02-05 20:46:14
【问题描述】:
我是编码新手,所以请耐心等待。 我正在开发一个用户上传 csv 的系统,我需要做的是显示内容,然后将其保存在数据库中。 (utf-8编码)
有人要求我解决一些法语字母字符显示不正确的问题。我几乎解决了这个问题,我正在显示诸如
之类的字符ÀàÂâÆÄäÇçÉéÈèÊêËëÎîÏïÔôœÖöÙùÛûÜüÿ
但是标题中提到的两个ŸŒ在网页上还没有正确显示。
到目前为止,这是我的 php 代码:
// say in the csv we have "ÖüÜߟÀàÂ"
$content = file_get_contents(addslashes($file_name));
var_dump($content) // output: string(54) "���ߟ��� "
if(!mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true)){
$data = iconv('macintosh', 'UTF-8', $content);
}
// deal with known encoding types
else if(mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true) == 'ISO-8859-1'){
//$data = mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true)); // does not work
$data = iconv('ISO-8859-1', 'UTF-8', $content); //does not work
}else if(mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true) == 'UTF-8'){
$data = $content
}
//if i print $data "Ÿ Œ " are not printed out... they got lost somewhere
//do more stuff here
我正在处理的文件的编码类型为ISO-8859-1(当我打印出mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true) 时,它显示ISO-8859-1)。
有没有人知道如何处理这种特殊情况?
【问题讨论】:
标签: php csv utf-8 character-encoding