HTML实体转换为PHP中的普通字符串 [英] HTML entities to normal strings in PHP

查看:110
本文介绍了HTML实体转换为PHP中的普通字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中有一个带有HTML实体的字符串.在html源代码中,我可以看到html实体,但是在输出中,我的字符串没有html实体.

I have a string with HTML entities in PHP. In html source i can see the html Entities but in the output my string is without html Entities.

喜欢:

HTML来源:

<a href="google.com" >Me&nbsp;You</a> ?<!-- output is Me YOU -->

如何在PHP中用(空格)替换&nbsp;? (以及所有其他HTML实体?)

How can i replace &nbsp; with (space) in PHP? (as well as all other HTML entities?)

我想要这个输出:

<a href="google.com" >Me You</a> ?<!-- output is Me YOU -->

推荐答案

请参阅:

函数html_entity_decode().

此函数解码a)对于所选文档类型必须有效的所有实体(包括所有数字实体),即,对于XML,此函数不解码某些DTD中可能定义的命名实体-和b)其一个或多个字符在与所选编码相关联的编码字符集中,并且在所选文档类型中允许使用.所有其他实体均保持不变.

This function decodes all the entities (including all numeric entities) that a) are necessarily valid for the chosen document type — i.e., for XML, this function does not decode named entities that might be defined in some DTD — and b) whose character or characters are in the coded character set associated with the chosen encoding and are permitted in the chosen document type. All other entities are left as is.

这篇关于HTML实体转换为PHP中的普通字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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