Mysql 에서 HTML 태그 삭제 함수(strip_tags)
@http://dev.mysql.com/doc/refman/5.1/en/string-functions.html
@http://stackoverflow.com/questions/2627940/remove-html-tags-from-record
@http://forums.mysql.com/read.php?52,177343,177985#msg-177985
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
'Database' 카테고리의 다른 글
MSSQL datetime 자료형을 string으로 형변환 (0) | 2017.11.15 |
---|---|
mysql 복구 (0) | 2016.06.14 |
select 시 순번(row number) 지정하기 (0) | 2014.09.19 |
MSSQL Express 백업스크립트 (0) | 2013.05.15 |
mysqldump 시 "Can't open file: './DB/table.frm' (errno: 24) when using LOCK TABLE" (0) | 2012.05.29 |