htmlentities在laravel中无法产生所需的输出 [英] htmlentities does not produce desired output in laravel

查看:101
本文介绍了htmlentities在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

我没有早点想到这个有点傻,但是要真正显示&lt;之类的东西,您需要更改&符.

I feel kind of silly for not thinking of this earlier, but to actually display &lt; and the like, you need to change the ampersand.

$variable = '<p></p>';
$var = '<code>'.htmlentities($variable).'</code>';
$var = str_replace('&','&amp;',$var);
echo $var;

它将按字面意义打印:&lt;p&gt;&lt;/p&gt;

That will print it literally: &lt;p&gt;&lt;/p&gt;

这是我粘贴的完全相同的内容,没有escaping code in Stack:< p></p>

Here is me pasting the exact same thing without escaping code in Stack: <p></p>

这篇关于htmlentities在laravel中无法产生所需的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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