ASP截取文章一部分显示(无损HTML)
vb Code复制内容到剪贴板
<% Function LeftH(str,l) dim labelt,labels dim ishtml ishtml=false dim res dim c,c2 dim n n=0 dim maxlen maxlen=len(str) dim i i=0 dim b,e do while n<l and i<maxlen i=i+1 c=mid(str,i,1) if c="<" then c2=mid(str,i+1,1) ishtml=true b=i end if res=res+c if ishtml=false then n=n+1 else if c=">" then if ishtml=true and c2<>"/" then labels=mid(str,b+1,i-b) e=InStr(labels," ") if e>0 then labels="</"+left(labels,e-1)+">" else labels="</"+labels end if labelt=labels+labelt end if ishtml=false end if end if loop leftH=res+labelt end function dim str str="<b><font color=red size=4 face=黑体>中华人</font>民共和国</b>" response.write "原始的效果:<br><br>"+str response.write "<script>alert('原始的html代码:"+str+"');</script>" response.write "<hr>" str=lefth(str,4) response.write "截取后的效果:<br><br>"+str response.write "<script>alert('截取后的html代码:"+str+"');</script>" %>
查看所有评论