PHP 解析问题 -  和 Â [英] PHP Parsing Problem -   and Â

查看:32
本文介绍了PHP 解析问题 -  和 Â的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试解析一些带有   的 html 然后 echo 它时, 变成"这个字符: Â.此外,html_entity_decode()str_replace() 不会改变它.

When I try to parse some html that has   sprinkled through it and then echo it, the   "turns into" this character: Â. Also, html_entity_decode() and str_replace() doesn't change it.

为什么会这样?如何删除 Â 的?

Why is this happening? How can I remove the Â's?

推荐答案

不间断空格存在于两个字节的UTF-8中:<代码>0xC2 和 0xA0.

The non-breaking space exist in UTF-8 of two bytes: 0xC2 and 0xA0.

当这些字节在 ISO-8859-1 中表示时(单字节编码)而不是 UTF-8(多字节编码),那么这些字节分别成为字符 Â 和另一个不间断空格 .

When those bytes are represented in ISO-8859-1 (a single-byte encoding) instead of UTF-8 (a multi-byte encoding) then those bytes becomes respectively the characters  and another non-breaking space .

显然您正在使用 UTF-8 解析 HTML 并使用 ISO-8859-1 回显结果.要解决此问题,您需要要么使用 ISO-8859-1 解析 HTML, 使用 UTF-8 回显结果.我建议一直使用 UTF-8.浏览 PHP UTF-8 备忘单 以将其全部对齐.

Apparently you're parsing the HTML using UTF-8 and echoing the results using ISO-8859-1. To fix this problem, you need to either parse HTML using ISO-8859-1 or echo the results using UTF-8. I'd recommend to use UTF-8 all the way. Go through the PHP UTF-8 cheatsheet to align it all out.

这篇关于PHP 解析问题 - &amp;nbsp;和 Â的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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