如何转换“西方(Mac OS Roman)"用PHP将文本格式化为UTF-8? [英] How can I convert "Western (Mac OS Roman)" formatted text to UTF-8 with PHP?

查看:168
本文介绍了如何转换“西方(Mac OS Roman)"用PHP将文本格式化为UTF-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Western(Mac OS Roman)中的Excel for Mac 2011 VBA导出的文件,如下所示:

I have files being exported by Excel for Mac 2011 VBA in Western (Mac OS Roman) as shown here:

我在

I haven't been successful in getting Excel for Mac VBA to export directly to UTF-8 so I want to convert these files with PHP before I save them to MySQL, I am using this command:

$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"

我发现此

I found this list of valid encoding formats from 2008, but none of them seem to represent 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

我需要使用什么格式将西方(Mac OS Roman)转换为UTF-8?

推荐答案

mb函数无法处理"macintosh",这是IANA为Mac Roman定义的名称.您必须使用iconv.

The mb-functions can't handle "macintosh" which is the IANA defined name for Mac Roman. You have to use iconv.

$line = iconv('macintosh', 'UTF-8', $line);

这篇关于如何转换“西方(Mac OS Roman)"用PHP将文本格式化为UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆