PHP htmlentities即使使用参数也不起作用

编程入门 行业动态 更新时间:2024-10-09 01:22:53
本文介绍了PHP htmlentities即使使用参数也不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当然,这已经被问过了,并已经寻找解决方案,但到目前为止,所有解决方案都还没有奏效.我想通过使用htmlentities或htmlspecialchars来将TM符号和&符号更改为它们的html等价物:

Of course this has been asked before and have searched for solutions, all which have not worked thus far. I want to change out the TM symbol and the ampersand to their html equivelents by using htmlentities or htmlspecialchars:

$TEST = "Kold Locker™ & other stuff"; echo "ORGINIAL: " . $TEST . "<BR/>"; echo "HTML: " . htmlentities($TEST, ENT_COMPAT, 'UTF-8');

这将显示:

ORGINIAL: Kold Locker™ & other stuff HTML:

我还尝试过使用htmlspecialchars进行尝试,并且更改了第二个参数,结果相同.

I have also tried it with htmlspecialchars and the second parameter changed with the same result.

我想念其他人声称在其他解决方案中有效的东西吗?

What am I missing that others have claimed worked in other solutions?

更新:我尝试仅显示utf8_encode($TEST),并且显示HTML: Kold Locker™ & other stuff

UPDATE: I tried just displaying utf8_encode($TEST) and it displayed HTML: Kold Locker™ & other stuff

推荐答案

您的代码对我有用:-?

Your code works for me :-?

在htmlentities() 的手册页中,我们可以阅读:

In the manual page for htmlentities() we can read:

返回值

返回编码的字符串.

如果输入字符串中包含无效的代码单元序列 给定的编码将返回一个空字符串,除非 设置了ENT_IGNORE或ENT_SUBSTITUTE标志.

If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.

我的猜测是输入数据未正确编码为UTF-8,并且该函数返回空字符串. (假设脚本没有崩溃,即该部分之后的代码仍在运行.)

My guess is that the input data is not properly encoded as UTF-8 and the function is returning an empty string. (Assuming that the script is not crashing, i.e., code after that part still runs.)

更多推荐

PHP htmlentities即使使用参数也不起作用

本文发布于:2023-10-26 06:49:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529391.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:也不   参数   PHP   htmlentities

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!