html_entity_decode 是否替换 还?如果不是怎么更换?
我遇到一种情况,我将字符串传递给函数。我想在将
传递给函数之前将其转换为“”(空格)。 html_entity_decode
可以吗?
如果不是怎么办?
我知道 str_replace
但还有其他出路吗?
I have a situation where I am passing a string to a function. I want to convert
to " " (a blank space) before passing it to function. Does html_entity_decode
does it?
If not how to do it?
I am aware of str_replace
but is there any other way out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
引用自
html_entity_decode()
手册:您可以使用
str_replace()
将 ascii 字符 #160 替换为空格:Quote from
html_entity_decode()
manual:You can use
str_replace()
to replace the ascii character #160 to a space:html_entity_decode 确实将
转换为空格,只是不是一个“简单”的空格(ASCII 32),而是一个不间断的空格(ASCII 160)(因为这是
的定义
)。如果您需要转换为 ASCII 32,您仍然需要
str_replace()
,或者根据您的情况,需要preg_match("/s+", ' ', $string)
code> 将各种空白转换为简单空格。html_entity_decode does convert
to a space, just not a "simple" one (ASCII 32), but a non-breaking space (ASCII 160) (as this is the definition of
).
If you need to convert to ASCII 32, you still need a
str_replace()
, or, depending on your situation, apreg_match("/s+", ' ', $string)
to convert all kinds of whitespace to simple spaces.是
请参阅 PHP 手册 http://php.net/manual/en/ function.html-entity-decode.php。
仔细阅读注释,也许这就是您面临的问题:
YES
See PHP manual http://php.net/manual/en/function.html-entity-decode.php.
Carefully read the Notes, maybe that s the issue you are facing:
不确定这对于大多数情况是否是可行的解决方案,但我在最近的应用程序中使用了
trim(strip_tags(html_entity_decode(htmlspecialchars_decode($html), ENT_QUOTES, 'UTF-8')));
。最初添加htmlspecialchars_decode()
是唯一真正能剥离它们的东西。Not sure if it is a viable solution for most cases but I used
trim(strip_tags(html_entity_decode(htmlspecialchars_decode($html), ENT_QUOTES, 'UTF-8')));
in my most recent application. The addition ofhtmlspecialchars_decode()
initially was the only thing that would actually strip them.