MySQL strip_tags

Posted by on November 4, 2011 | 0 comments

Berikut adalah salah satu fungsi yang dapat digunakan untuk untuk melakukan strip_tags pada query MySQL.


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 )) ;

UNTIL sstart < 1 END REPEAT;
END IF;
RETURN X;
END;
||

Cara penggunaannya :


mysql> SELECT strip_tags('<a href="http://gulangguling.com"><B>Click!!</B></a>') as strip_tags;

+------------+
| strip_tags |
+------------+
| Click!!     |
+------------+

note: Penggunaan function ini pada data yang banyak atau perkalian query yang banyak dapat menyebabkan slowness pada system anda.

credit : http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

Leave a Comment

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Security Code: