求救!asp调用去除html标签的function函数!

凡夫与俗子 2009-06-26 10:59:17
我是asp新人,我用了个html标签的函数,单独页的,要去除数据库里p_info的html标签然后在显示页里显示出来,两个页面如下,请问该怎么调用这个函数啊?ClearHtml(Content)这里的centent要改成p_info吗?显示页里除了包含函数页面还要加什么代码才能调用函数?

函数页:

HTML code<%
'/* 函数名称:Zxj_ReplaceHtml ClearHtml
'/* 函数语言:VBScript Language
'/* 作  用:清除文件HTML格式函数
'/* 传递参数:Content (注:需要进行清除的内容)
'/* 函数作者:张晓军(古城童话) QQ:382511147
'/* 函数说明:正则匹配(正则表达式)模式进行数据匹配替换

Function ClearHtml(Content)
Content=Zxj_ReplaceHtml("&#[^>]*;", "", Content)
Content=Zxj_ReplaceHtml("</?marquee[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("</?object[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("</?param[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("</?embed[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("</?table[^>]*>", "", Content)
Content=Zxj_ReplaceHtml(" ","",Content)
Content=Zxj_ReplaceHtml("</?tr[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("</?th[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?p[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?a[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?img[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?tbody[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?li[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?span[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?div[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?th[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("</?td[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("</?script[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("(javascript|jscript|vbscript|vbs):", "", Content)
Content=Zxj_ReplaceHtml("on(mouse|exit|error|click|key)", "", Content)
Content=Zxj_ReplaceHtml("<\\?xml[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("<\/?[a-z]+:[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("</?font[^>]*>", "", Content)
Content=Zxj_ReplaceHtml("</?b[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?u[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?i[^>]*>","",Content)
Content=Zxj_ReplaceHtml("</?strong[^>]*>","",Content)
ClearHtml=Content
End Function

Function Zxj_ReplaceHtml(patrn, strng,content)
IF IsNull(content) Then
content=""
End IF
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = true ' 设置忽略字符大小写。
regEx.Global = True ' 设置全局可用性。
Zxj_ReplaceHtml=regEx.Replace(content,strng) ' 执行正则匹配
End Function
%>


显示页:

HTML code<% Option Explicit %>
<!--#Include file="conn.asp"-->
<!--#Include file="fun.asp"-->
<html>
<head>
<title>信息</title>
</head>
<body>
<center>
<table border="0" width="100%">
<tr bgcolor="#B7B7B7" align="center">
<td width=10%>编号</td>
<td width=10%>备注</td>

</tr>
<%
Dim rs,strSql
set rs=server.CreateObject("ADODB.Recordset")
strSql ="select * from products where p_id=179"
rs.open strSql,conn,1,1

if not(rs.bof or rs.eof) Then

Response.Write "<tr bgcolor='#E6E6E6' align='center'>"
Response.Write "<td>" & rs("p_bh") & "</td>"
Response.Write "<td>" & rs("p_info") & " </td>"
Response.Write "</tr>"
else
Response.Write "暂无数据"



end if
rs.close
set rs=nothing
conn.close
set db=nothing
%>
</center>
</body>
</html>

...全文
226 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
暖暖~ 2011-07-29
  • 打赏
  • 举报
回复
我也刚开始学 来看看
tang3402 2010-07-25
  • 打赏
  • 举报
回复
用正则表达式不是更简单吗?非要用上面那死办法?
function ClearHtml(htmlcode)
Dim Re
Re = New RegExp
Re.IgnoreCase = True
Re.Pattern = "<.*?>"
ClearHtml=RegReplace("<.*?>",htmlcode)
End Function
凡夫与俗子 2009-06-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lzp4881 的回复:]
Response.Write " <td>" & ClearHtml(rs("p_info")) & " </td>"
[/Quote]
谢谢大哥!搞定
lzp4881 2009-06-26
  • 打赏
  • 举报
回复
Response.Write " <td>" & ClearHtml(rs("p_info")) & " </td>"

28,391

社区成员

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

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