[英]How can I remove special characters in a PHP string?
I am getting output as 我得到输出为
FBI believed he had a ‘doomsday device’
instead of 代替
FBI believed he had a ‘doomsday device’
when i am using 当我在使用
iconv("UTF-8", "ISO-8859-1//IGNORE", $topic);
output is 输出是
FBI believed he had a âdoomsday deviceâ
I am not using any header or charset in my file. 我没有在我的文件中使用任何标题或字符集。
Update 更新
Got why is this happening 知道为什么会这样
when the UTF-8 series of numbers is interpreted as if it were ISO-8859-1 the output is 当UTF-8系列数字被解释为输出为ISO-8859-1时
’ ’
Explaination 释
0xE28099 breaks down as 0xE2 (â), 0x80 (€) and 0x99 (™). 0xE28099分解为0xE2(â),0x80(€)和0x99(™)。 What was one character in UTF-8 (') gets mistakenly displayed as three (’) when misinterpreted as ISO-8859-1.
当被误解为ISO-8859-1时,UTF-8(')中的一个字符错误地显示为三个(?)。
Still no solution to convert it 仍然没有解决方案来转换它
Well the output page is being interpreted in Windows-1252
, not ISO-8859-1.. 那么输出页面正在
Windows-1252
解释,而不是ISO-8859-1。
I recommend setting your header charset to utf-8: 我建议将标题字符集设置为utf-8:
In apache config: 在apache配置中:
AddDefaultCharset utf-8
Php.ini: 在php.ini:
default_charset utf-8
Manually in php: 在php中手动:
header("Content-Type: text/html; charset=utf-8");
If you cannot do anything of the above because of some weird reasons, you should then convert into Windows-1252 instead: 如果由于一些奇怪的原因你不能做上述任何事情,你应该转换成Windows-1252:
iconv("UTF-8", "Windows-1252//IGNORE", $topic);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.