SQL查找并替换html文本

时间:2013-11-01 12:58:06

标签: html sql replace

我想在SQL数据库中将html字符串替换为另一个字符串。我知道主要语法,但字符串有html标签。

以下是一个例子:

update wp_posts 
set post_content = replace(post_content, '<img alt="100%" id="home-img" src="/wp-content/themes/wp-theme/images/100pc.png">'
, '<a href="fblink" target="_blank" class="facebook"></a><img alt="100%" id="home-img" src="/wp-content/themes/wp-theme/images/100pc.png">'
);

我想我应该知道这个的正确语法,但我认为问题是“,&gt;,=字符。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

这是一个SQL Fiddle,它表明您使用的是正确的语法。你也可以使用

update wp_posts 
set post_content = '<a href="fblink" target="_blank" class="facebook"></a><img alt="100%" id="home-img" src="/wp-content/themes/wp-theme/images/100pc.png">'
WHERE post_content = '<img alt="100%" id="home-img" src="/wp-content/themes/wp-theme/images/100pc.png">';