我有Excel因Mac 2011 VBA导出的文件 西方(Mac OS Roman) 如下所示:

alt text

我还没有成功 让Mac VBA直接导出到UTF-8 因此,我想在将这些文件保存到mySQL之前使用PHP转换这些文件,我正在使用此命令:

$dataset[$k] = mb_convert_encoding($line, 'ASCII', 'UTF-8'); //not correctly converted
$dataset[$k] = mb_convert_encoding($line, 'ISO-8859-8', 'UTF-8'); //not correctly converted
$dataset[$k] = mb_convert_encoding($line, 'macintosh', 'UTF-8'); //unrecognized name
$dataset[$k] = mb_convert_encoding($line, 'Windows-1251', 'UTF-8'); //changes "schön" to "schљn"
$dataset[$k] = mb_convert_encoding($line, 'Windows-1252', 'UTF-8'); //changes "schön" to "schšn"

我找到了这个 有效编码格式列表 从2008年开始,但它们似乎都没有代表 Western (Mac OS Roman).

* UCS-4
* UCS-4BE
* UCS-4LE
* UCS-2
* UCS-2BE
* UCS-2LE
* UTF-32
* UTF-32BE
* UTF-32LE
* UTF-16
* UTF-16BE
* UTF-16LE
* UTF-7
* UTF7-IMAP
* UTF-8
* ASCII
* EUC-JP
* SJIS
* eucJP-win
* SJIS-win
* ISO-2022-JP
* JIS
* ISO-8859-1
* ISO-8859-2
* ISO-8859-3
* ISO-8859-4
* ISO-8859-5
* ISO-8859-6
* ISO-8859-7
* ISO-8859-8
* ISO-8859-9
* ISO-8859-10
* ISO-8859-13
* ISO-8859-14
* ISO-8859-15
* byte2be
* byte2le
* byte4be
* byte4le
* BASE64
* HTML-ENTITIES
* 7bit
* 8bit
* EUC-CN
* CP936
* HZ
* EUC-TW
* CP950
* BIG-5
* EUC-KR
* UHC (CP949)
* ISO-2022-KR
* Windows-1251 (CP1251)
* Windows-1252 (CP1252)
* CP866 (IBM866)
* KOI8-R

我需要使用哪种格式将“ Western(Mac OS Roman)转换为UTF-8?

有帮助吗?

解决方案

MB函数无法处理“ Macintosh”,这是Mac Roman的IANA定义名称。你必须使用 iconv.

$line = iconv('macintosh', 'UTF-8', $line);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top