htmlentities在laravel中无法产生所需的输出 [英] htmlentities does not produce desired output in laravel
问题描述
例如,我在laravel4控制器中使用htmlentities
I use the htmlentities in a laravel4 controller for example like this
$varialble = htmlentities("<p></p>");
echo $variable;
//Output is <p></p>
不是实体版本.
有人可以指出我该如何解决.
Can someone point me how to fix this.
推荐答案
H.这让我陷入了循环.
Hah. This threw me for a loop.
检查一下: PHP htmlspecialchars无法正常工作
Don't worry. htmlspecialchars() is encoding the < and > characters properly. It is just that when you echo the encoded string to your computer screen, your browser helpfully decodes the characters again. If you view the page source you will see the encoded string.
@Peter_Carter
Don't worry. htmlspecialchars() is encoding the < and > characters properly. It is just that when you echo the encoded string to your computer screen, your browser helpfully decodes the characters again. If you view the page source you will see the encoded string.
@Peter_Carter
我没有早点想到这个有点傻,但是要真正显示<
之类的东西,您需要更改&符.
I feel kind of silly for not thinking of this earlier, but to actually display <
and the like, you need to change the ampersand.
$variable = '<p></p>';
$var = '<code>'.htmlentities($variable).'</code>';
$var = str_replace('&','&',$var);
echo $var;
它将按字面意义打印:<p></p>
That will print it literally: <p></p>
这是我粘贴的完全相同的内容,没有escaping code in Stack
:< p></p>
Here is me pasting the exact same thing without escaping code in Stack
: <p></p>
这篇关于htmlentities在laravel中无法产生所需的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!