ASP去除字段中的HTML
从网上找了一个去除HTML的ASP函数:Functionnohtml(str)DimreSetre=newRegExpre.IgnoreCase=Truere.Globa...
从网上找了一个去除HTML的ASP函数:
Function nohtml(str)
Dim re
Set re=new RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern="(\<.*?\>)"
str=re.replace(str,"")
re.Pattern="(\<\/.*?\>)"
str=re.replace(str,"")
nohtml=str
End Function
想用这个函数去除数据库中这个字段:ArticleInfoRs("Content") 里面的HTML代码,
函数调用格式为:<%=left(nohtml(ArticleInfoRs("Content")),50)%>,
但是运行后显示:类型不匹配: 'ArticleInfoRs',
这是什么原因呢?正确的写法应该是什么?谢谢了! 展开
Function nohtml(str)
Dim re
Set re=new RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern="(\<.*?\>)"
str=re.replace(str,"")
re.Pattern="(\<\/.*?\>)"
str=re.replace(str,"")
nohtml=str
End Function
想用这个函数去除数据库中这个字段:ArticleInfoRs("Content") 里面的HTML代码,
函数调用格式为:<%=left(nohtml(ArticleInfoRs("Content")),50)%>,
但是运行后显示:类型不匹配: 'ArticleInfoRs',
这是什么原因呢?正确的写法应该是什么?谢谢了! 展开
2个回答
展开全部
哎....
1. 把这段代码领存为一个文件,比如叫a.asp放在和你这个页面的同一级目录下
<%
'去除html标记
Function nohtml(str)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="<[^<>]*>"
str=re.replace(str,"")
nohtml=str
End Function
Function gotTopic(str,strlen)
if str="" then
gotTopic=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then exit for
next
if i < l then
gotTopic=left(str,i) & "..."
else
gotTopic=str
end if
'gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
End Function
%>
2. 然后你的这个显示页面包含一这个文件
<!--#include file="a.asp"-->
3. 再然后
把你页面上的<%function ....%>删了
1. 把这段代码领存为一个文件,比如叫a.asp放在和你这个页面的同一级目录下
<%
'去除html标记
Function nohtml(str)
dim re
Set re=new RegExp
re.IgnoreCase =true
re.Global=True
re.Pattern="<[^<>]*>"
str=re.replace(str,"")
nohtml=str
End Function
Function gotTopic(str,strlen)
if str="" then
gotTopic=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then exit for
next
if i < l then
gotTopic=left(str,i) & "..."
else
gotTopic=str
end if
'gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
End Function
%>
2. 然后你的这个显示页面包含一这个文件
<!--#include file="a.asp"-->
3. 再然后
把你页面上的<%function ....%>删了
追问
照你说的做了 代码存为文件nohtml.asp, 运行后显示:
未结束的字符串常量
nohtml.asp,行 18
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
------------------^
能不能帮忙改一下 ? 十分感谢!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询