在ASP中,从数据库读取内容,只显示纯文本怎么弄?
答案:4 悬赏:0
解决时间 2021-02-21 06:43
- 提问者网友:騷女、無惡不作
- 2021-02-20 23:06
我的数据库中的内容是HTML格式的!如果直接读出来的话是HTML格式!我只想读出来内容中的纯文本,过滤掉HTML语言,应该怎么做?哪位高手知道的请告诉俺一声!
最佳答案
- 二级知识专家网友:强势废物
- 2021-02-20 23:36
<%
Function RemoveHTML(strHTML)
ON ERROR RESUME NEXT
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<.+?>"
strOutput = objRegExp.Replace(strHTML, "")
strOutput = Replace(strOutput, "<", "〈")
strOutput = Replace(strOutput, ">", "〉")
strOutput = Replace(str0utput, "", "")
RemoveHTML = strOutput
Set objRegExp = Nothing
End Function
%>
然后在你想要输出的地方写入:<%=RemoveHTML(rs("字段名"))%>就搞定了!
Function RemoveHTML(strHTML)
ON ERROR RESUME NEXT
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<.+?>"
strOutput = objRegExp.Replace(strHTML, "")
strOutput = Replace(strOutput, "<", "〈")
strOutput = Replace(strOutput, ">", "〉")
strOutput = Replace(str0utput, "", "")
RemoveHTML = strOutput
Set objRegExp = Nothing
End Function
%>
然后在你想要输出的地方写入:<%=RemoveHTML(rs("字段名"))%>就搞定了!
全部回答
- 1楼网友:承载所有颓废
- 2021-02-21 00:36
Function RemoveHTML(str)
Dim re
Set re=New RegExp
re.Pattern="<.*?>"
re.IgnoreCase=True
re.Global=True
str=re.Replace(str,"")
Set re=Nothing
RemoveHTML=str
End Function
过滤掉html字符 只需要输出的时候调用以下就ok
- 2楼网友:情窦初殇
- 2021-02-21 00:29
可以用fso逐行读取
<%
set fso=server.createobject("scripting.filesystemobject")
set txtfile=fso.opentextfile(server.mappath("text.txt"))
while not txtfile.atendofstream
response.write "" & txtfile.readline & "
"
。。写入数据库
wend
txtfile.close
%>
也可以 直接连接数据库,从文本中直接读取
insert into tbl select * openrowset('microsoft.jet.oledb.4.0', 'text;hdr=no;delimited="::";database=d:\',tmp#txt)
另外还可以用bcp导入文本到数据库
类似的样式:
exec master..xp_cmdshell ’bcp "dbname..tablename" in c:“dt.txt -c -sservername -usa -ppassword’
仅供参考,具体写法请查资料,注意路径和文件名
- 3楼网友:邪性洒脱
- 2021-02-21 00:06
刚刚回了一次,现在再回一次,哈哈
过滤html,但不删除任何不是html的东西,如英文字符等。
Function delHtml(strHtml)
Dim objRegExp, strOutput
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "(<[a-zA-Z].*?>)|(<[\/][a-zA-Z].*?>)"
strOutput = objRegExp.Replace(strHtml, "")
strOutput = Replace(strOutput, "<", "<")
strOutput = Replace(strOutput, ">", ">")
delHtml = strOutput
Set objRegExp = Nothing
End Function
如果你还过滤别的什么东东
直接加代码如:
把文章中的“某某某”换成“XXX”
strOutput = Replace(strOutput, "某某某", "XXX")
把文章中的“ ”删除
strOutput = Replace(strOutput, " ", "")
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯