博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
domdocument40_DOMDocument和UTF-8问题
阅读量:2512 次
发布时间:2019-05-11

本文共 1126 字,大约阅读时间需要 3 分钟。

domdocument40

A few weeks back I shared how I used to reliably update all image URLs from standard HTTP to HTTPS.  DOMDocument made a difficult problem seem incredibly easy ... but with one side-effect that it took me a while to spot:  UTF-8 characters were being mutated into another set of characters.  I was seeing a bunch of odd characters like "ãç³" and"»ã®é" all over each blog post.

几周前,我分享了如何使用可靠地将所有图像URL从标准HTTP更新为HTTPS。 DOMDocument使一个棘手的问题似乎变得异常容易……但是有一个副作用,我花了一段时间才发现:UTF-8字符被突变为另一组字符。 我在每个博客文章中看到一堆奇怪的字符,例如“ãç³”和“»ã®é”。

I knew the problem was happening during the DOMDocument parsing and that I need to find a fix quickly.  The solution was just a tiny bit of code:

我知道在DOMDocument解析期间会发生问题,因此我需要快速找到修复程序。 解决方案只是一小段代码:

// Create a DOMDocument instance $doc = new DOMDocument();// The fix: mb_convert_encoding conversion$doc->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));

After setting the character set with mb_convert_encoding, the odd characters vanished and the desired characters were back in place.  Phew!

mb_convert_encoding设置字符集mb_convert_encoding ,奇数字符消失了,所需的字符又恢复了原位。 !

翻译自:

domdocument40

转载地址:http://czpwd.baihongyu.com/

你可能感兴趣的文章
数据库三大范式
查看>>
工作总结之二:bug级别、优先级别、bug状态
查看>>
访问修饰符、封装、继承
查看>>
更换pip源到国内镜像,提升pip下载速度.
查看>>
POJ 2265 Bee Maja (找规律)
查看>>
Kendo MVVM 数据绑定(七) Invisible/Visible
查看>>
[zz]kvm环境使用libvirt创建虚拟机
查看>>
bzoj1059 [ZJOI2007]矩阵游戏
查看>>
插入返回ibatis 的selectKey 实现插入数据后获得id
查看>>
vim 程序编辑器
查看>>
LIS(单调队列优化 C++ 版)(施工ing)
查看>>
刚接触Vuex
查看>>
四种加载React数据的技术对比(Meteor 转)
查看>>
Airthmetic_Approching
查看>>
操作文本文件
查看>>
公司项目的几个问题
查看>>
解决win7下打开Excel2007,报“向程序发送命令时出现问题”的错误
查看>>
Velocity快速入门教程
查看>>
关于集合常见的问题
查看>>
车牌正则表达式
查看>>