首页 > 代码库 > 过滤字段中HTML标签
过滤字段中HTML标签
代码中只是过滤了一部分标签,例如span这些还是没有过滤,如果有更好办法的,可以帮忙补充
create FUNCTION [dbo].[CleanHTML] (@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,‘ ‘,‘‘)
RETURN LTRIM(RTRIM(@HTMLText))
END
过滤字段中HTML标签