MySQL查找和替换HTML DOM标签
有如下一个html字符串保存在mysql数据库中:
<div> <p>文本</p> <figure>广告<imgsrc="a.jpg"/></figure> <p>文本</p> </div>
现在要从数据库数据中删除中间的广告标签,如何用mysql语句实现?
我们要用到两个主要函数:LOCATE和INSERT。
第1步一句mysql查找
首先,如果我们用一句mysql语句:
select Insert( post_content, Locate('<figure>',post_content), Locate('</figure>',post_content,Locate('<figure>',post_content))-Locate("<figure>",post_content)+LENGTH('</figure>'), '' ) asnew_contentfromwp_postswhereID=146;
- LOCATE(
substr
,str)