DELIMITER $$
USE `db`$$
DROP FUNCTION IF EXISTS `strip_tags`$$
CREATE FUNCTION `strip_tags`($str TEXT, $tag TEXT) RETURNS TEXT CHARSET utf8
BEGIN
DECLARE $START, $END INT DEFAULT 1;
SET $str = COALESCE($str, '');
LOOP
SET $START = LOCATE(CONCAT('<', $tag), $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, '');
SET $str = REPLACE($str, CONCAT('', $tag, '>'), '');
END LOOP;
END$$
DELIMITER ;
Пример:
-- Удаляем тэги a
SELECT
STRIP_TAGS(description, 'a') AS stripped
FROM
table;
-- Удаляем все тэги
SELECT
STRIP_TAGS(description, '') AS stripped
FROM
table;
Источник: https://stackoverflow.com/questions/7654436 назад в раздел mysql
Чт 14 Мар 2019.