zoukankan      html  css  js  c++  java
  • 在SQL中用正则表达式替换html标签

    create function [dbo].[clearhtml] (@maco varchar(8000))
    returns varchar(8000)
    as
    begin
        declare @randchar_one nvarchar(200)
        declare @randchar_two nvarchar(200)
           if(charindex('<<',@maco)>0)
                  begin
                         set @randchar_one='D4678B36-B958-4274-B81E-BBA636CFB427';
                         set @randchar_two='49E374CC-9E1A-4850-897C-27074DE32E7F';
                         set @maco=replace(@maco,'<<',@randchar_one)
                         set @maco=replace(@maco,'>>',@randchar_two)
                  end
        declare @i int
        while 1 = 1
        begin
           set @i=len(@maco)
           set @maco=replace(@maco, substring(@maco,charindex('<',@maco),
           charindex('>',@maco)-charindex('<',@maco)+1),space(0))
           if @i=len( @maco )
           break
        end
     
        set @maco=replace(@maco,' ','')
        set @maco=replace(@maco,' ','')
        set @maco=ltrim(rtrim(@maco))
        set @maco=replace(@maco,char(9),'')
        set @maco=replace(@maco,char(10),'')
        set @maco=replace(@maco,char(13),'')
        if(charindex(@randchar_one,@maco)>0)
        begin
           set @maco=replace(@maco,'D4678B36-B958-4274-B81E-BBA636CFB427','<<')
           set @maco=replace(@maco,'49E374CC-9E1A-4850-897C-27074DE32E7F','>>')
        end
        return (@maco)
    end
    
    declare @mark varchar(8000)
    set @mark='<body><div id=u><a href=http://passport.baidu.com/?login&tpl=mn>登录</a></div><center><img src=http://www.baidu.com/img/baidu_logo.gif width=270 height=129 usemap="#mp" id=lg><br><br><br><br><table cellpadding=0 cellspacing=0 id=l><tr><td><div id=m><a onclick=s(this) href=http://news.baidu.com>新 闻</a><b>网 页</b><a onclick=s(this) href=http://tieba.baidu.com>贴 吧</a><a onclick=s(this) href=http://zhidao.baidu.com>知 道</a><a onclick=s(this) href=http://mp3.baidu.com>MP3</a><a onclick=s(this) href=http://image.baidu.com>图 片</a><a onclick=s(this) href=http://video.baidu.com>视 频</a></div></td></tr></table>
    <table cellpadding=0 cellspacing=0 style="margin-left:15px"><tr valign=top><td style="height:62px;padding-left:92px" nowrap><div style="position:relative"><form name=f action=/s><input type=text name=wd id=kw size=42 maxlength=100> <input type=submit value=百度一下id=sb><div id=sug onselectstart="return false"></div><span id=hp><a href=/search/jiqiao.html>帮助</a><br><a href=/gaoji/advanced.html>高级</a></span></form></div></td></tr></table>
    </body>'
    select dbo.clearhtml(@mark)
    --result
    --登录新闻网页贴吧知道MP3图片视频帮助高级
    


  • 相关阅读:
    你应该了解Nginx的7个原因
    linux 中php以及nginx的重启命令
    HTTP 长连接和短连接
    git常用命令
    Linux 防火墙开放特定端口 (iptables)
    redis配置文件相关
    关于解决emoji表情的存储
    文件内容统计——Linux wc命令
    Git 服务器搭建
    关于微信二次分享,描述变链接的解决方法(一)----文档说明
  • 原文地址:https://www.cnblogs.com/smartsmile/p/6234164.html
Copyright © 2011-2022 走看看