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;和 Â
基础教程推荐
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php中的foreach复选框POST 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的PDF导出 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
