SQLServer 移除HTML函数

分类:SQL     发布:2019-12-18     来源:本站     浏览:639 次
--使用方法:SELECT TOP 10 SUBSTRING(dbo.RemoveHtml(content), 1, 50) + '...' summary FROM RC_Blog_Article

ALTER   FUNCTION [dbo].[RemoveHtml] ( @HTMLText VARCHAR(MAX) )
RETURNS VARCHAR(MAX)
AS 
    BEGIN
        DECLARE @Start INT
        DECLARE @End INT
        DECLARE @Length INT
        SET @Start = CHARINDEX('<', @HTMLText)
        SET @End = CHARINDEX('>', @HTMLText, CHARINDEX('<', @HTMLText))
        SET @Length = ( @End - @Start ) + 1
        WHILE @Start > 0
            AND @End > 0
            AND @Length > 0 
            BEGIN
                SET @HTMLText = STUFF(@HTMLText, @Start, @Length, '')
                SET @Start = CHARINDEX('<', @HTMLText)
                SET @End = CHARINDEX('>', @HTMLText, CHARINDEX('<', @HTMLText))
                SET @Length = ( @End - @Start ) + 1
            END
        SET @HTMLText = REPLACE(@htmlText, ' ', '')
        SET @HTMLText = REPLACE(@htmlText, '"', '"')
        SET @HTMLText = REPLACE(@htmlText, '&', '&')
        SET @HTMLText = REPLACE(@htmlText, '€', '€')
        SET @HTMLText = REPLACE(@htmlText, '<', '<')
        SET @HTMLText = REPLACE(@htmlText, '>', '>')
        SET @HTMLText = REPLACE(@htmlText, 'œ', 'oe')
        SET @HTMLText = REPLACE(@htmlText, ' ', ' ')
        SET @HTMLText = REPLACE(@htmlText, '©', '?')
        SET @HTMLText = REPLACE(@htmlText, '«', '?')
        SET @HTMLText = REPLACE(@htmlText, '®', '?')
        SET @HTMLText = REPLACE(@htmlText, '±', '±')
        SET @HTMLText = REPLACE(@htmlText, '²', '2')
        SET @HTMLText = REPLACE(@htmlText, '³', '3')
        SET @HTMLText = REPLACE(@htmlText, 'µ', 'μ')
        SET @HTMLText = REPLACE(@htmlText, '·', '·')
        SET @HTMLText = REPLACE(@htmlText, 'º', 'o')
        SET @HTMLText = REPLACE(@htmlText, '»', '?')
        SET @HTMLText = REPLACE(@htmlText, '¼', '?')
        SET @HTMLText = REPLACE(@htmlText, '½', '?')
        SET @HTMLText = REPLACE(@htmlText, '¾', '?')
        SET @HTMLText = REPLACE(@htmlText, '&Aelig', '?')
        SET @HTMLText = REPLACE(@htmlText, 'Ç', '?')
        SET @HTMLText = REPLACE(@htmlText, 'È', 'è')
        SET @HTMLText = REPLACE(@htmlText, 'É', 'é')
        SET @HTMLText = REPLACE(@htmlText, 'Ê', 'ê')
        SET @HTMLText = REPLACE(@htmlText, 'Ö', '?')
        SET @HTMLText = REPLACE(@htmlText, 'à', 'à')
        SET @HTMLText = REPLACE(@htmlText, 'â', 'a')
        SET @HTMLText = REPLACE(@htmlText, 'ä', '?')
        SET @HTMLText = REPLACE(@htmlText, 'æ', '?')
        SET @HTMLText = REPLACE(@htmlText, 'ç', '?')
        SET @HTMLText = REPLACE(@htmlText, 'è', 'è')
        SET @HTMLText = REPLACE(@htmlText, 'é', 'é')
        SET @HTMLText = REPLACE(@htmlText, 'ê', 'ê')
        SET @HTMLText = REPLACE(@htmlText, 'ë', '?')
        SET @HTMLText = REPLACE(@htmlText, 'î', '?')
        SET @HTMLText = REPLACE(@htmlText, 'ô', '?')
        SET @HTMLText = REPLACE(@htmlText, 'ö', '?')
        SET @HTMLText = REPLACE(@htmlText, '÷', '÷')
        SET @HTMLText = REPLACE(@htmlText, 'ø', '?')
        SET @HTMLText = REPLACE(@htmlText, 'ù', 'ù')
        SET @HTMLText = REPLACE(@htmlText, 'ú', 'ú')
        SET @HTMLText = REPLACE(@htmlText, 'û', '?')
        SET @HTMLText = REPLACE(@htmlText, 'ü', 'ü')
        SET @HTMLText = REPLACE(@htmlText, '"', '"')
        SET @HTMLText = REPLACE(@htmlText, '&', '&')
        SET @HTMLText = REPLACE(@htmlText, '‹', '<')
        SET @HTMLText = REPLACE(@htmlText, '›', '>')
        RETURN LTRIM(RTRIM(@HTMLText))
    END 
        

如果觉得文章对您有帮助,您可以对我进行打赏 ¥0.69 元(金额随机^_^,每次刷新金额不同)。

请使用支付宝扫码支付

留言评论

*称  呼:
*联系方式: 方便与您取得联系,推荐使用邮箱。
*内  容:

已有评论

暂无数据

上一篇:Java Post提交表单辅助类

下一篇:DES 对称加密(C#实现加密,Java可解密)