PHP htmlspecialchars is not working [closed]

2020-07-09 06:07发布

问题:

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
<?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.