使用另一个表中的数据查找和替换列中的字符串?

时间:2011-11-07 00:50:10

标签: php mysql string replace find

我有:

表-A:

  

ID |的 POST_CONTENT

     

1 |这是bla bla url1.com

     

2 |这是另一个文本blah blah url2.com

     

3 |这是第三个文本blah blah url3.com

     

4 | wordpress blogposts有很多这样的文章文本,里面有更多匹配的字符串

     

5 | ...

*表-B:*

  

StringsA | StringsB

     

url1.com | link1.com

     

url2.com | link2.com

     

url3.com | link3.com

     

... url600 | ... link600

表A中的post_content是wordpress文章文本,可能在本文的某处包含一些字符串,与StringsA中的字符串匹配。

我需要使用StringsB中相应的字符串替换post_content列中的字符串,所以它看起来像这样:

表-A:

  

ID |的 POST_CONTENT

     

1 |这是bla bla link1.com

     

2 |这是另一个文字blah blah link2.com

     

3 |这是第三篇文章blah blah link3.com

     

4 | wordpress blogposts有很多这样的文章文本,里面有更多匹配的字符串

     

5 | ...

最简单的方法是什么?我可以只使用MySQL,还是应该使用PHP脚本?

1 个答案:

答案 0 :(得分:0)

请参阅http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

当然,你可以仔细查询......

update Table_A, Table_B set post_content=replace(post_content, StringsA, StringsB)