PHP Parsing Problem - amp;nbsp; and #194;(PHP 解析问题 - amp;nbsp;和 )
问题描述
当我尝试解析一些带有 的 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 解析问题 - &nbsp;和 Â的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 解析问题 - &nbsp;和 Â
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
