PHP,将 UTF-8 转换为 ASCII 8 位

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11843407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:15:38  来源:igfitidea点击:

PHP, convert UTF-8 to ASCII 8-bit

phpencodingutf-8asciiiconv

提问by Daniel

I'm trying to convert a string from UTF-8 to ASCII 8-bit by using the iconvfunction. The string is meant to be imported into an accounting software (some basic instructions parsed accordingly to SIE standards).

我正在尝试使用该iconv函数将字符串从 UTF-8 转换为 ASCII 8 位。该字符串旨在导入会计软件(根据 SIE 标准解析的一些基本指令)。

What I'm running now:

我现在正在运行的内容:

iconv("UTF-8", "ASCII", $this->_output)

This works for accounting software #1, but software #2 complains about the encoding. Specified encoding by the standard is: IBM PC 8-bit extended ASCII (Codepage 437).

这适用于会计软件 #1,但软件 #2 抱怨编码。标准指定的编码是:IBM PC 8-bit extended ASCII (Codepage 437).

My question is, what version of ASCII is PHP encoding my string into, and if other than specified - how can I encode the string accordingly to the standard specification?

我的问题是,PHP 将我的字符串编码到哪个版本的 ASCII 中,如果不是指定的 - 我该如何根据标准规范对字符串进行编码?

回答by Vlad Balmos

try this for the software #2

试试这个软件#2

iconv("UTF-8", "CP437", $this->_output);

Extended ASCII is not the same as plain ASCII. The first one maybe accepts ASCII, but the second software requires Extended ASCII - Codepage 437

扩展 ASCII 与普通 ASCII 不同。第一个可能接受 ASCII,但第二个软件需要扩展 ASCII - 代码页 437

see this link

看到这个链接