Als je inhoud altijd begint met tags( etc.)
probeer dit:
SELECT * from table WHERE colmn_name REGEXP '>[^<]*mytext';
Een andere manier is om strip_tags
te gebruiken — Verwijder HTML- en PHP-tags uit een string
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>
Uitvoer van bovenstaande code:
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>
Waarschuwing ::Because strip_tags() does not actually validate the HTML, partial or broken tags can result in the removal of more text/data than expected.
Je moet de html-code in een variabele zetten, laten we zeggen $html_input
$html_input= "'<p>text between tag 'p'</p><span>text between 'span'</span>'";
$stripped_html = strip_tags($html_input);
// Now insert it into the table `text`
INSERT INTO `text` VALUES (1, $striped_html);
Puur MYSQL
manier:
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
Referentie:Stackoverflow