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