我需要删除表格中列的所有链接。所以对于这样的列条目:
American drama film directed by <a href="http://www.google.com">Richard LaGravenese</a>
我需要删除整个链接,所以它最终会像这样:
American drama film directed by Richard LaGravenese
有没有办法用一个UPDATE语句执行此操作? (MySQL的)
答案 0 :(得分:0)
答案 1 :(得分:0)
您可以创建strip_tags
功能。
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;
<强>输出强>
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