2014-01-24 40 views
0

期望输出I使用ヶ辆在laravel4控制器例如这样ヶ辆不产生laravel

$varialble = htmlentities("<p></p>"); 

echo $variable; 

//Output is <p></p> 

不是实体的版本。

有人可以指点我如何解决这个问题。

+0

怎么样'用htmlspecialchars()'? –

+0

相同的输出队友。感谢您的帮助。 –

+0

在输入字符串中没有需要编码为HTML实体的字符。试试urlencode或@kcdwayne公开的内容 –

回答

0

哈。这给我一个循环。

检查了这一点:PHP htmlspecialchars is not working

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;之类的,你需要改变的符号。

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

这将字面上打印:&lt;p&gt;&lt;/p&gt;

这里被我贴上同样的事情,而不escaping code in Stack:<p> </P >

+1

这是伴侣的现身。可能看起来很明显,但至少这是世界上少一个问题。谢谢。 –