亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從記錄中刪除HTML標簽

從記錄中刪除HTML標簽

侃侃爾雅 2019-10-10 16:54:30
需要幫助從具有以下內容的表一列構成MYSQL查詢Row1 : this is first <a href='mytext.txt'>row</a> from the tableRow 2 : THis is the second row <img src ='mytext.jpg'> my image is thereRow 3 : <p>This is the Third row  my mytext is there  </p>Row 4 : <p class='te_mytext'>This is the Third row  my text is there  </p>這是表格行,我嘗試將關鍵字搜索為“ mytext”我的查詢是SELECT * from table  WHERE colmn_name ` like '%mytext%' "我將得到所有4行作為結果,但結果是錯誤的。我只需要第3行就可以得到正確的輸出。之所以只在內容中包含mytext的該行不在內容中,而是在所有行中都具有mytext的原因,如何編寫MySQL查詢?
查看完整描述

3 回答

?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

這是我對strip_tags函數的實現:


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


查看完整回答
反對 回復 2019-10-10
?
Smart貓小萌

TA貢獻1911條經驗 獲得超7個贊

這些行添加到fnStripTags功能

后SET Dirty = Insert( Dirty, iStart, iLength, '');


set Dirty = Replace(Dirty,'&nbsp;',''); #No space between & and nbsp;

set Dirty = Replace(Dirty,'\r','');

set Dirty = Replace(Dirty,'\n','');


查看完整回答
反對 回復 2019-10-10
  • 3 回答
  • 0 關注
  • 447 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號