本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7590152
建立时间:2006年5月29日




[算法]html代码过滤
软件技术

lhwork 发表于 2006/8/23 9:46:26

/**     * This method takes a string which may contain HTML tags (ie, &lt;b&gt;,     * &lt;table&gt;, etc) and converts the '&lt'' and '&gt;' characters to     * their HTML escape sequences.     *     * @param input the text to be converted.     * @return the input string with the characters '&lt;' and '&gt;' replaced     *  with their HTML escape sequences.     */    public static final String escapeHTMLTags( String input )    {        //Check if the string is null or zero length -- if so, return        //what was sent in.        if( input == null || input.length() == 0 )        {            return input;        }        //Use a StringBuffer in lieu of String concatenation -- it is        //much more efficient this way.        StringBuffer buf = new StringBuffer( input.length() );        char ch = ' ';        for( int i = 0; i < input.length(); i++ )        {            ch = input.charAt( i );            if( ch == '<' )            {                buf.append( "&lt;" );            }            else if( ch == '>' )            {                buf.append( "&gt;" );            }            else if( ch == '&' )            {                buf.append( "&amp;" );            }            else if( ch == '"' )            {                buf.append( "&quot;" );            }            else            {                buf.append( ch );            }        }        return buf.toString();    }


阅读全文(4008) | 回复(1) | 编辑 | 精华
 


回复:html代码过滤
软件技术

fff(游客)发表评论于2007/6/26 14:00:39

<html> <forn>


个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


» 1 »

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.309 second(s), page refreshed 144770021 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号