asp显示不要HTML语言

来源:百度知道 编辑:UC知道 时间:2024/05/31 12:03:24
由于文章是WORD直接拷进去的,数据库里就有很多HTML语言
在前台显示的时候,我想只显示文本(内容提要页面)。意思就是不管多大的字只要是9PT,不过什么格式都不要。
请问在ASP里怎么实现啊
我是初入行的,请详细一点,谢谢!
4楼 的朋友,我用你的方法,但是输出的是空白呀。
<%
function nohtml(str)
dim re
Set re=new RegExp
str=re.replace(str,"<br>","{br}")
re.IgnoreCase =true
re.Global=True
re.Pattern="(\<.[^\<]*\>)"
str=re.replace(str," ")
re.Pattern="(\<\/[^\<]*\>)"
str=re.replace(str," ")
nohtml=re.replace(str,"{br}","<br>")
set re=nothing
end function
%>
<%=left(nohtml(Rs("NewsContain")),100)%>...
然后页面看到的就只有...
还请多指教,新手,呵呵

可以自定义一个清除HTML标签的函数。如下所示:
<%
function nohtml(str)
dim re
Set re=new RegExp
str=re.replace(str,"<br>","{br}")
re.IgnoreCase =true
re.Global=True
re.Pattern="(\<.[^\<]*\>)"
str=re.replace(str," ")
re.Pattern="(\<\/[^\<]*\>)"
str=re.replace(str," ")
nohtml=re.replace(str,"{br}","<br>")
set re=nothing
end function
%>
除了原有文字和换行符保留外,其他一律过滤掉了

忘了补充一句,比如需要输出没有格式的正文的时候,直接调用该函数即可。如:
response.write nohtml(rs("content"))

拷贝的时候将WORD里拷出来的先粘贴到记事本里,再拷贝到数据库里就好了 去掉格式了

先清除文章中相关的HTML标签就可以了。