2013-07-03 22 views
0

我有一个wordpress网站,需要在每个包含特定单词(例如this-link)的特定链接之后添加string rel="nofollow"。我有这个字符串:如何在MySQL中包含特定字符的字符串中添加字符串

a href="http://www.this-link-is.com/ANYTHING" 

,需要add rel="nofollow"包含此链接每个字符串后:
a href="http://www.this-link-is.com/ANYTHING" rel="nofollow"

所以它应该像

update wp_posts set post_content = replace(post_content, '%this-link%>', '%this-link% rel="nofollow">'); 

我怎么能这样做?谢谢。

+0

可能重复的http://计算器.COM /问题/ 5524872/MySQL的,追加字符串 – Naeem

回答

1

你在找什么是REGEXP_REPLACE功能。你需要把它定义为一个UDF,如:

https://launchpad.net/mysql-udf-regexp

从该链接使用REGEXP_REPLACE UDF,查询会再看看这样的:

UPDATE `wp_posts` 
SET `wp_content` = REGEXP_REPLACE(`wp_content`, '(this-link[^"]+")', '\1 rel="nofollow') 
WHERE `link` LIKE '%this-link%'; 
相关问题