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

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

问题描述

当我尝试解析一些具有& nbsp; 的html,然后通过 echo & nbsp; 变成这个字符:。此外, 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解析问题 - & nbsp;和Â的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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