如何将“Western (Mac OS Roman)”转换为“Western (Mac OS Roman)”使用 PHP 将文本格式化为 UTF-8?

发布于 2024-10-12 10:13:27 字数 1830 浏览 1 评论 0原文

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

“alt

我没有成功 让 Excel for 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 年有效编码格式列表,但它们似乎都不代表西方(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?

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

alt text

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

What format do I need to use to convert "Western (Mac OS Roman) to UTF-8?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌辣 2024-10-19 10:13:27

mb-functions 无法处理“macintosh”,这是 IANA 为 Mac Roman 定义的名称。您必须使用 iconv。

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文