Hvis dit indhold altid starter med tags (osv.)
prøv dette:
SELECT * from table WHERE colmn_name REGEXP '>[^<]*mytext';
En anden måde er at bruge strip_tags
— Fjern HTML- og PHP-tags fra en streng
<?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 af ovenstående kode:
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>
Advarsel ::Because strip_tags() does not actually validate the HTML, partial or broken tags can result in the removal of more text/data than expected.
Du bør sætte html-koden i en variabel, lad os sige $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);
Rent MYSQL
måde:
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
Reference:Stackoverflow