首页 > 编程 > Regex > 正文

正则表达式教程:去除内容中的html

2020-03-16 21:24:39
字体:
来源:转载
供稿:网友
本文将为大家介绍如何使用正则表达式去除文章内容中的HTML代码。具体代码如下:

  1. <% 
  2. Option Explicit 
  3.  
  4. Function stripHTML(strtext) 
  5. dim arysplit,i,j, strOutput 
  6. arysplit=split(strtext,"<"
  7.  
  8.   if len(arysplit(0))>0 then j=1 else j=0 
  9.  
  10.   for i=j to ubound(arysplit) 
  11.      if instr(arysplit(i),">") then 
  12.        arysplit(i)=mid(arysplit(i),instr(arysplit(i),">")+1) 
  13.      else 
  14.        arysplit(i)="<" & arysplit(i) 
  15.      end if 
  16.   next 
  17.  
  18.   strOutput = join(arysplit, ""
  19.   strOutput = mid(strOutput, 2-j) 
  20.   strOutput = replace(strOutput,">",">"
  21.   strOutput = replace(strOutput,"<","<"
  22.  
  23.   stripHTML = strOutput 
  24. End Function 
  25.  
  26.  
  27. %> 
  28.  
  29. <form method="post" id=form1 name=form1> 
  30.   <b>Enter an HTML String:</b><br> 
  31.   <textarea name="txtHTML" cols="50" rows="8" wrap="virtual"><%=Request("txtHTML")%></textarea> 
  32.   <p> 
  33.   <input type="submit" value="Strip HTML Tags!" id=submit1 name=submit1> 
  34. </form> 
  35.  
  36. <% if Len(Request("txtHTML")) > 0 then %> 
  37.     <p><hr><p> 
  38.     <b><u>View of string <i>with no</i> HTML stripping:</u></b><br> 
  39.     <xmp> 
  40.     <%=Request("txtHTML")%> 
  41.     </xmp><p> 
  42.     <b><u>View of string <i>with</i> HTML stripping:</u></b><br> 
  43.     <pre> 
  44.     <%=StripHTML(Request("txtHTML"))%> 
  45.     </pre> 
  46. <% End If %> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表