如果您对mysql去除html标签的函数代码和mysql去掉指定字符感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解mysql去除html标签的函数代码的各种细节,并对mysql去掉指定字符进行
如果您对mysql去除html标签的函数代码和mysql去掉指定字符感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解mysql去除html标签的函数代码的各种细节,并对mysql去掉指定字符进行深入的分析,此外还有关于asp 正则实现清除html文本格式的函数代码、asp去除html的函数代码分析附实例说明、ASP正则过滤HTML标签的函数、c# 取出特定标签的内容 去除html标签的实用技巧。
本文目录一览:- mysql去除html标签的函数代码(mysql去掉指定字符)
- asp 正则实现清除html文本格式的函数代码
- asp去除html的函数代码分析附实例说明
- ASP正则过滤HTML标签的函数
- c# 取出特定标签的内容 去除html标签
mysql去除html标签的函数代码(mysql去掉指定字符)
mysql本身没有去除html代码的内置函数,但是在一些情况下,不得不在数据库层次提取一些去除了html代码的纯文本。
经过谷歌后,找到了以下两个函数,经测试,均可用。
函数1:
SQL代码
SET GLOBAL log_bin_trust_function_creators=1;
DROP FUNCTION IF EXISTS fnStripTags;
DELIMITER |
CREATE FUNCTION fnStripTags( Dirty varchar(4000) )
RETURNS varchar(4000)
DETERMINISTIC
BEGIN
DECLARE iStart, iEnd, iLength int;
WHILE Locate( '<', Dirty ) > 0 And Locate( '>', Dirty, Locate( '<', Dirty )) > 0 DO
BEGIN
SET iStart = Locate( '<', Dirty ), iEnd = Locate( '>', Dirty, Locate('<', Dirty ));
SET iLength = ( iEnd - iStart) + 1;
IF iLength > 0 THEN
BEGIN
SET Dirty = Insert( Dirty, iStart, iLength, '');
END;
END IF;
END;
END WHILE;
RETURN Dirty;
END;
|
DELIMITER ;
SELECT fnStripTags('this <html>is <b>a test</b>, nothing more</html>');
函数2:
SQL代码
CREATE FUNCTION `strip_tags`($str text) RETURNS text
BEGIN
DECLARE $start, $end INT DEFAULT 1;
LOOP
SET $start = LOCATE("<", $str, $start);
IF (!$start) THEN RETURN $str; END IF;
SET $end = LOCATE(">", $str, $start);
IF (!$end) THEN SET $end = $start; END IF;
SET $str = INSERT($str, $start, $end - $start + 1, "");
END LOOP;
END;
select strip_tags('<span>hel<b>lo <a href="world">wo<>rld</a> <<x>again<.');
本文章网址:http://www.ppssdd.com/code/1671.html。转载请保留出处,谢谢合作!asp 正则实现清除html文本格式的函数代码
<%
''/* 函数名称: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
%>
- ASP中过滤UBB和Html标签
- ScriptHtml 函数之过滤html标记的asp代码
- asp CutStrX字符串截取函数(过滤全部HTML标记)
- ASP.NET过滤HTML字符串方法总结
- ASP.NET过滤HTML标签只保留换行与空格的方法
- asp中实现清除html的函数
asp去除html的函数代码分析附实例说明
下面这段代码,不会替换ld<sad中间的<,所以内容仍然是正常的
<%
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," ")
str=replace(str," ","")
str=replace(str," ","")
nohtml=str
set re=nothing
end function
str="<title>sadjksjdl欢迎你sajdljsald<sadsadsad<br>" ''这里是测试
response.write nohtml(str)
%>