简体   繁体   English

移除所有<div tags with sql query< div><div id="text_translate"><p> 我有表名wp_posts并且在post_content列中有我的帖子的描述(HTML 格式)。</p><p> 我想要一个在 post_content 列中搜索并选择以<div class or no class>开头的标签并删除整个标签的查询。</p><p> 我不想删除标签内的任何内容,只需删除标签</p><p>这个:</p><pre> <div> or <div clas="sada"> some text </div></pre><p> 会变成这样:</p><pre> some text</pre><p> 我的 MYSQL 版本是 15.1。</p></div></div>

[英]Remove all <div tags with SQL Query

I have table name wp_posts and in post_content column there is a description of my posts (in HTML).我有表名wp_posts并且在post_content列中有我的帖子的描述(HTML 格式)。

I would like to have a query that searches in post_content column and selects the tag starting with <div class or no class> and remove whole tag.我想要一个在 post_content 列中搜索并选择以<div class or no class>开头的标签并删除整个标签的查询。

I dont want to remove anything inside the tag, just remove the tag我不想删除标签内的任何内容,只需删除标签

This:这个:

<div> or <div clas="sada">
some text
</div>

Would become this:会变成这样:

some text

My MYSQL version is 15.1.我的 MYSQL 版本是 15.1。

In your case you can write a short script which fetch all wp_posts elements.在您的情况下,您可以编写一个简短的脚本来获取所有 wp_posts 元素。 Then you iterate this collection and remove with reg.然后你迭代这个集合并用 reg 删除。 expression function the div tags and update the field again in your database.表达式 function div 标记并再次更新数据库中的字段。

This would be the expression which remove the div tag.这将是删除 div 标签的表达式。 $wp_content = preg_replace('/\<[\/]{0,1}div[^\>]*\>/i', '', $wp_content);

if you are using wordpress, you must have php access, so you can use strip_tags() to remove the html from the variable.如果您使用的是 wordpress,则必须具有 php 访问权限,因此您可以使用 strip_tags() 从变量中删除 html。

I find a solution here , write it here for others:我在这里找到解决方案, 在这里写给其他人:

update wp_posts
set post_content = REGEXP_REPLACE(post_content, '</?div.*?>', '');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM