好吧,我知道这很旧,但是我认为您可以通过在以下位置创建此功能来解决您的问题mysql
:
DELIMITER |
DROP FUNCTION IF EXISTS plain_text |
CREATE FUNCTION plain_text( Dirty text )
RETURNS text
DETERMINISTIC
BEGIN
DECLARE iStart, iEnd, iLength int;
WHILE Locate( '<', Dirty ) > 0 And Locate( '>', Dirty, Locate( '<', Dirty )) > 0 DO
BEGIN
SET iStart = Locate( '<style>', Dirty ), iEnd = Locate( '</style>', Dirty);
IF iEnd > 0 THEN
BEGIN
SET iLength = ( iEnd - iStart) + 12;
END;
ELSE
BEGIN
SET iStart = Locate( '<', Dirty ), iEnd = Locate( '>', Dirty, Locate('<', Dirty ));
SET iLength = ( iEnd - iStart) + 1;
END;
END IF;
IF iLength > 0 THEN
BEGIN
SET Dirty = Insert( Dirty, iStart, iLength, '');
END;
END IF;
END;
END WHILE;
RETURN Dirty;
END;
|
DELIMITER ;
此函数删除所有 html 标签以及<style></style>
标签之间的所有内容。
然后你可以像这样进行查询:
SELECT plain_text(ANSWER) as plain_t FROM FAQ HAVING (plain_t LIKE '%".$searchKey."%')