SQL中过滤HTML

 
    
1 SET GLOBAL log_bin_trust_function_creators = 1 ;
2   DROP FUNCTION IF EXISTS fnStripTags;
3 DELIMITER |
4 CREATE FUNCTION fnStripTags( Dirty varchar ( 4000 ) )
5 RETURNS varchar ( 4000 )
6 DETERMINISTIC
7 BEGIN
8 DECLARE iStart, iEnd, iLength int ;
9 WHILE Locate( ' < ' , Dirty ) > 0 And Locate( ' > ' , Dirty, Locate( ' < ' , Dirty )) > 0 DO
10 BEGIN
11 SET iStart = Locate( ' < ' , Dirty ), iEnd = Locate( ' > ' , Dirty, Locate( ' < ' , Dirty ));
12 SET iLength = ( iEnd - iStart) + 1 ;
13 IF iLength > 0 THEN
14 BEGIN
15 SET Dirty = Insert ( Dirty, iStart, iLength, '' );
16 END ;
17 END IF ;
18 END ;
19 END WHILE ;
20 RETURN Dirty;
21 END ;
22 |
23 DELIMITER ;
24 SELECT fnStripTags( ' this is a test, nothing more ' );

 

转载于:https://www.cnblogs.com/wangbin/archive/2010/12/09/1901428.html

你可能感兴趣的:(SQL中过滤HTML)