CSDN博客

img samlover

去处HTML的函数

发表于2004/12/31 16:25:00  595人阅读

javascript实例参考网站
http://www.jxyc.gov.cn/blog/withwolf/index.asp?vt=default&page=14

<SCRIPT LANGUAGE="VBScript">
Function ClearHTML(jnkcV)
    Dim jnkcTmp,jnkcRegExp
    jnkcTmp = jnkcV & ""
    Set jnkcRegExp = new RegExp
    jnkcRegExp.Global = True
    jnkcRegExp.Pattern = "(/[[^/]]*/])"
    jnkcTmp = jnkcRegExp.Replace(jnkcTmp,"")
    jnkcRegExp.Pattern = "(<[^>]*>)"
    jnkcTmp = jnkcRegExp.Replace(jnkcTmp,"")
    Set jnkcRegExp = Nothing
    ClearHTML = jnkcTmp
End Function
MsgBox ClearHTML("[url]http://www.xiaobin.net[/url]  <a href=#>Withwolf</a>")
</SCRIPT>

          
     //html代码屏蔽
     public  static String filterStr(String str){
               if(str==null)return null;
            StringBuffer sb = new StringBuffer();            
           int n = str.length();
           for (int i = 0; i < n; i++) {
                  char c = str.charAt(i);
                  switch (c) {                  
                          case ' ': sb.append("&nbsp;");break;
                    case '':sb.append("<br/>");break;
                    case '/'':sb.append("'");break;
                    
                    case '<': sb.append("<"); break;
                    case '>': sb.append(">"); break;
                    case '&': sb.append("&"); break;
                    case '"': sb.append("""); break;                        
                    default:  sb.append(c);
              }
        }
        return sb.toString();
    }
      
0 0

相关博文

我的热门文章

img
取 消
img