asp里有:
<textarea><%=Server.HTMLEncode(rs("content"))%></textarea>
不知道php里是否有类似的方法。
也可以直接自己替换
把<替换成&lt;等

解决方案 »

  1.   

    将从TEXTAREA中取出的内容用htmlspecialchars算一下就OK了。
      

  2.   

    方法又很多,你可以自己写一个替调违法字符的函数,也可以用PHP自带的,如楼上所说,只要在插入数据库之前用函数处理一下就行了!
    //剔除非法的字符
    function delscript($word)
    {
    for($j=0;$j<strlen($word);$j++){
    if(substr($word,$j,1)=="<")$word=substr($word,0,$j)."&lt;".substr($word,$j+1);
    }
    for($j=0;$j<strlen($word);$j++){
    if(substr($word,$j,1)==">")$word=substr($word,0,$j)."&gt;".substr($word,$j+1);
    }
    for($j=0;$j<strlen($word);$j++){
    if(ord(substr($word,$j,1))==13)$word=substr($word,0,$j)."<br>".substr($word,$j+2);
    }
    return $word;
    }
      

  3.   

    楼主可以参考以下代码<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body><form>
    <textarea rows="27" name="test" cols="80">
    <?php
    $str="<textarea>abc</textarea>";
    $str_out=htmlspecialchars($str);
    echo $str_out;
    ?>
    </textarea>
    </form></body>
    </html>