Jika konten Anda selalu diawali dengan tag( dll.)
coba ini:
SELECT * from table WHERE colmn_name REGEXP '>[^<]*mytext';
Cara lain adalah dengan menggunakan strip_tags
— Menghapus tag HTML dan PHP dari 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>');
?>
Output dari kode di atas:
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>
Peringatan ::Because strip_tags() does not actually validate the HTML, partial or broken tags can result in the removal of more text/data than expected.
Anda harus memasukkan kode html ke dalam variabel, misalkan $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);
Murni MYSQL
cara:
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
Referensi:Stackoverflow