Mysql 에서 HTML 태그 삭제 함수(strip_tags)

Mysql 에서 HTML 태그 삭제 함수(strip_tags)

delimiter ||
DROP FUNCTION IF EXISTS strip_tags||
CREATE FUNCTION strip_tags( x longtext) RETURNS longtext
	LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA
	BEGIN
		DECLARE sstart INT UNSIGNED;
		DECLARE ends INT UNSIGNED;
		IF x IS NOT NULL THEN
			SET sstart = LOCATE('<', x, 1);
		REPEAT
			SET ends = LOCATE('>', x, sstart);
			SET x = CONCAT(SUBSTRING( x, 1 ,sstart -1) ,SUBSTRING(x, ends +1 )) ;
			SET sstart = LOCATE('<', x, 1);
			UNTIL sstart < 1 
		END REPEAT;
	END IF;
	return x;
END;
||
delimiter ;

@http://dev.mysql.com/doc/refman/5.1/en/string-functions.html

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;

@http://stackoverflow.com/questions/2627940/remove-html-tags-from-record

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 ;

@http://forums.mysql.com/read.php?52,177343,177985#msg-177985