PHP htmlspecialchars无法正常工作 [英] PHP htmlspecialchars is not working

查看:133
本文介绍了PHP htmlspecialchars无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php  
    $new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);  
    echo $new;  
?>

输出应为

& lt;a href=& #039;test& #039;&gt;Test& lt;/a& gt; 

但输出是

&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;

推荐答案

不用担心. 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.

这篇关于PHP htmlspecialchars无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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