php 用htmlspecialchars

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 用htmlspecialchars相关的知识,希望对你有一定的参考价值。

 <?php 
       $text1 = "HTMLSPECIALCHARS <Click> & learn more";
       $text2 = "☺❀♺©™₽";
     
       $url_page = "php/page/url.php";
       $param1 = "this is a sctring width < >";
       $param2 = "&#?*$[]+ are bad chars";
       $linktext = "<Clicl> & click";
       
       $url = "http://localhost/";
       $url .= rawurlencode($url_page);
       $url .= "?" . "param1=" . urlencode($param1);
       $url .= "&" . "param2=" . urlencode($param2);
    ?>
    
       
          <p><?php echo  htmlspecialchars($text1); ?></p><br>
          <p><?php echo  htmlentities($text2); ?></p><br>
          <p><?php echo htmlspecialchars($url); ?></p>

<?php 
 $text1 = "<Clicl> & click";
 echo htmlspecialchars($text1); //> &lt;Clicl&gt; &amp; click
 

 $text2 = "<Clicl> & click";
 echo urlencode($text2); //> %3CClicl%3E+%26+click
 

 $text3 = "<Clicl> & click";
 echo rawurlencode($text3); //> %3CClicl%3E%20%26%20click 

?>

以上是关于php 用htmlspecialchars的主要内容,如果未能解决你的问题,请参考以下文章

152-PHP htmlspecialchars函数

php 恢复htmlspecialchars

php map_htmlspecialchars

php htmlentities和htmlspecialchars 的区别

PHP htmlentities 和 htmlspecialchars的区别

PHP函数htmlspecialchars不起作用[重复]