2013-07-03 27 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%'; 
相關問題