Commit 7b5ec8d8 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Add MySQl strip_tags() function

parent 1221dca8
Pipeline #2423 passed with stages
in 3 minutes and 8 seconds
......@@ -6860,6 +6860,21 @@ Output::
hello world-
.. _strip_tags:
strip_tags: strip html tags
^^^^^^^^^^^^^^^^^^^^^^^^^^^
The SQL function strip_tags(input) returns 'input' without any HTML tags.
Example::
10.sql = SELECT strip_tags('<a href="https://example.com"><b>my name</b> <i>is john</i></a> - end of sentence')
Output::
my name is john - end of sentence
.. _download:
Download
......
......@@ -83,3 +83,23 @@ BEGIN
SET output = IF(input = '', token, input);
RETURN output;
END;
###
#
# strip_tags(input) - copied from https://stackoverflow.com/questions/2627940/remove-html-tags-from-record
#
DROP FUNCTION IF EXISTS strip_tags;
CREATE FUNCTION `strip_tags`(str TEXT)
RETURNS TEXT
DETERMINISTIC
SQL SECURITY INVOKER
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;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment