htmlspecialchars()  函数把一些预定义的字符转换为 HTML 实体。

解决方案 »

  1.   


    htmlspecialchars只转换 &、""、'、<、>'&' (ampersand) becomes '&amp;' 
    '"' (double quote) becomes '&quot;' when ENT_NOQUOTES is not set. 
    ''' (single quote) becomes '&#039;' only when ENT_QUOTES is set. 
    '<' (less than) becomes '&lt;' 
    '>' (greater than) becomes '&gt;' 
      

  2.   

    <?php 
    function html2txt($document){ 
    $search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript 
                   '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags 
                   '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly 
                   '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments including CDATA 
    ); 
    $text = preg_replace($search, '', $document); 
    return $text; 

     $act=html2txt($_POST['act']);
         $title=html2txt($_POST['title']);
         $content=html2txt($_POST['content']);
    ?>  这个足够强大了
      

  3.   

    可以转为实体,或者直接过滤html/javascript标签。
      

  4.   

    这个函数把<script>等标签都直接过滤掉了,最好是可以转成实体的。
      

  5.   

    插入的时候用 addslashes
    输出的时候用 stripcslashes
    试一下。