0

i need to remove all links form column in a table. So for column entry like this:

 American drama film directed by <a href="http://www.google.com">Richard LaGravenese</a>

i need to remove the entire link, so it would end up like this:

American drama film directed by Richard LaGravenese

Is there a way to do this with a single UPDATE statement? (mysql)

HAHAHA
  • 9
  • 1

2 Answers2

0

you can do it running a regular expression

try using mysql-udf-regexp

take a look to this post, it can be useful

How to do a regular expression replace in MySQL?

Community
  • 1
  • 1
cristallo
  • 1,951
  • 2
  • 25
  • 42
0

You can create strip_tags function.

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;

Output

mysql> select strip_tags('<span>hel<b>lo <a href="world">wo<>rld</a> <<x>again<.');
+----------------------------------------------------------------------+
| strip_tags('<span>hel<b>lo <a href="world">wo<>rld</a> <<x>again<.') |
+----------------------------------------------------------------------+
| hello world again.                                                   |
+----------------------------------------------------------------------+
1 row in set

Thanks to the post https://stackoverflow.com/a/13347316/2689199

Community
  • 1
  • 1
Gopal Joshi
  • 2,350
  • 22
  • 49