PHP htmlspecialchars is not working [closed]

笑着哭i 提交于 2019-12-12 09:37:07

问题


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

output should be

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

but output is

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

回答1:


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.



来源:https://stackoverflow.com/questions/5114579/php-htmlspecialchars-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!