Se i tuoi contenuti iniziano sempre con i tag (ecc.)
prova questo:
SELECT * from table WHERE colmn_name REGEXP '>[^<]*mytext';
Un altro modo è utilizzare strip_tags
— Elimina i tag HTML e PHP da una stringa
<?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>');
?>
Output del codice sopra:
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>
Avviso ::Because strip_tags() does not actually validate the HTML, partial or broken tags can result in the removal of more text/data than expected.
Dovresti inserire il codice html in una variabile, diciamo $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);
Semplicemente MYSQL
modo:
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
Riferimento:Stackoverflow