Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在MySQL表中查找并替换字符串_Php_Mysql_Css_Wordpress - Fatal编程技术网

Php 在MySQL表中查找并替换字符串

Php 在MySQL表中查找并替换字符串,php,mysql,css,wordpress,Php,Mysql,Css,Wordpress,我希望更新WordPress数据库中的表,我对我希望实现的目标充满信心,它不会造成任何损害,我正在努力实现我想要的目标 在post_内容字段中有: 现在我想用 我知道如何更新表格,但我无法确定如何匹配我希望更新的内容。 我想在课程末尾添加“img responsive”类 如果你只是在做这一个领域,那么 UPDATE your_table SET post_content = REPLACE(post_content, '<img class="%"', '<img class="

我希望更新WordPress数据库中的表,我对我希望实现的目标充满信心,它不会造成任何损害,我正在努力实现我想要的目标

在post_内容字段中有:

现在我想用

我知道如何更新表格,但我无法确定如何匹配我希望更新的内容。 我想在课程末尾添加“img responsive”类


如果你只是在做这一个领域,那么

UPDATE your_table 
SET post_content = REPLACE(post_content, '<img class="%"', '<img class="% img-responsive') WHERE post_content LIKE '%aligncenter  wp-image-1603%'
UPDATE your_table 
SET post_content = REPLACE(post_content, '<img class="', '<img class="img-responsive ') WHERE post_content LIKE '%<img class="%'
或者,如果您需要更广泛的内容,例如所有内容图像,那么

UPDATE your_table 
SET post_content = REPLACE(post_content, '<img class="%"', '<img class="% img-responsive') WHERE post_content LIKE '%aligncenter  wp-image-1603%'
UPDATE your_table 
SET post_content = REPLACE(post_content, '<img class="', '<img class="img-responsive ') WHERE post_content LIKE '%<img class="%'
当然,这将假定类是所有图像标记的第一个属性


顺便说一句:请确保通过先选择运行任何脚本,以确保获取所需内容!:

我认为您不能在替换中使用通配符%。 试试这个


为什么不更新主题的函数以在呈现post_内容时添加类?然后可以保持数据库的原样。或者有一个wordpress的搜索和替换插件可以实现这一点:。我假设你想处理帖子内容中的所有图像,或者只是在它们有aligncenter类的地方?
UPDATE your_table 
SET post_content = REPLACE(post_content, '<img class="', '<img class="img-responsive ') WHERE post_content LIKE '%<img class="%'
UPDATE your_table SET post_content = REPLACE(post_content,SUBSTRING_INDEX(SUBSTRING_INDEX(post_content,'" title="',1),'<img class="',-1),
                                                   CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(post_content,'" title="',1),'<img class="',-1),' img-responsive'))
WHERE post_content like '%<img class="%"'