怎样把从数据库里读出来的文本里的html代码去掉?

jervis82 2004-04-09 08:20:23
如题.
...全文
96 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxrl 2004-04-13
  • 打赏
  • 举报
回复
偶靠 都揭帖了啊
chinalinx 2004-04-11
  • 打赏
  • 举报
回复
保存为CHAR.inc文件
<%
function htmlencode(str)
dim result
if isNULL(str) then
htmlencode=""
exit function
end if
result=str
result = replace(result, "&", "&")
result = replace(result, ">", ">")
result = replace(result, "<", "<")
result = replace(result, chr(34),""")
result = replace(result,chr(32)," ",1)
result = replace(result, chr(13)&chr(10), "<BR>",1)
HTMLEncode = result
end function

function HTMLDecode(str)
dim result
if isNULL(str) then
htmlencode=""
exit function
end if
result=str
result = replace(result, ">", ">")
result = replace(result, "<", "<")
result = replace(result," ",chr(32))
result = replace(result, """,chr(34))
result = replace(result, "<BR>", chr(13)&CHR(10))
result = replace(result, "&","&" )
HTMLDecode = result
end function
%>

aa.asp
<!--#include file="CHAR.inc"-->
<%
response.write htmlencode(rs("aa"))
%>
jervis82 2004-04-11
  • 打赏
  • 举报
回复
没有人有成功的代码吗?
jervis82 2004-04-11
  • 打赏
  • 举报
回复
如果我有图片的话,那么图片也就不再去显示.总之就是只要那些文字.
jervis82 2004-04-11
  • 打赏
  • 举报
回复
唉............我是说输出后只是文本.在页面中你查看原文件也看不到那些html的那种.

如:在数据库中有这样的字符串
<body>aaaa</body>

那么我想的效果是显示后只是
aaaa

用记事本打开查看也只是
aaaa
jervis82 2004-04-10
  • 打赏
  • 举报
回复
郁闷
wolfsky1994 2004-04-10
  • 打赏
  • 举报
回复
Server.HTMLEncode( string )
xrwang 2004-04-10
  • 打赏
  • 举报
回复
我的思路是这样的,如果能用正则表达式最好,
不能用可以这么试试(没有测试,很可能有语法错误):
function CutHTMLTag(strHaveHTML)
dim nBeginPos,nEndPos,strHaveHTML,strHTMLTag
strHaveHML="这是一个<STRONG>测试</STRONG>字符串,需要被删除HTML标记"
do while true
nBeginPos=InStr(1,strHaveHTML,"<") '得到HTML标记中"<"的位置
if nBeginPos<1 then '如果没找到,说明已经没有HTML标记了
CutHTMLTag=strHaveHTML
exit function
else
nEndPos=InStr(1,strHaveHTML,">") '得到HTML标记中的">"位置
if nEndPos<1 then '如果没找到,退出
CutHTMLTag=strHaveHTML
exit function
else
strHTMLTag=Mid(strHaveHTMLTag,nBeginPos,nEndPos-nBeginPos) '得到HTML标记
'注意:这里并不严谨,没有判断得到的strHTMLTag是否真为HTML标记,实现的是否可以和现有的所有HTML标记一一比较
StrHaveHTML=Replace(strHaveHTML,strHTMLTag,"") '将该HTML标记用空字符串代替
end if
end if
loop
end function
jervis82 2004-04-10
  • 打赏
  • 举报
回复
top
jervis82 2004-04-10
  • 打赏
  • 举报
回复
兄弟们,我说的是要把文本里的html代码都去掉.
例如: <body>去掉代码</body>
那么最后得到的结果是: 去掉代码
lystan 2004-04-10
  • 打赏
  • 举报
回复
Server.HTMLEncode( string )就可以了
jervis82 2004-04-09
  • 打赏
  • 举报
回复
自己再顶.没有人答就算.
chating 2004-04-09
  • 打赏
  • 举报
回复
Server.HTMLEncode( string )

Server.URLEncode( string )

第二个,看需要不需要,可以不用的
jervis82 2004-04-09
  • 打赏
  • 举报
回复
我不会正则表达式.

谁有代码?我急用.
snowcloud2002 2004-04-09
  • 打赏
  • 举报
回复
使用正则表达式替换原数据中的html代码

如ttkkyy的,他的意思是替换所有包含"<",">"标记的内容为空字符串从而达到你要的
jervis82 2004-04-09
  • 打赏
  • 举报
回复
有人可以说得详细点吗?
上面那段用不了.
ttkkyy 2004-04-09
  • 打赏
  • 举报
回复
<SCRIPT LANGUAGE="VBScript">
<!--
content="<html><head><title>内容编辑</title></head><body>内容111111</body></html>"
function RemoveHTML(fString)
dim re
set re = New RegExp
re.Global = True
re.IgnoreCase = True
're.MultiLine = True
if not isnull(fString) then
re.Pattern = "<(.[^>]*)>"
fString = re.Replace(fString,"")
RemoveHTML = fString
end if
end function

msgbox RemoveHTML (content)
//-->
</SCRIPT>

你改一下应该就可以用了
jervis82 2004-04-09
  • 打赏
  • 举报
回复
顶一下

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧