Because many links that reference documents outside the site are invalid, a large number of dead links are generated, which is unfriendly to search engines and is not conducive to website optimization, therefore, the out-of-site link filtering function is added to the site. For newly added articles, the rel = "nofollow" label is automatically added when the library is added, see "add external link Filtering for site content". For filtering when data is called at the front-end, the speed at which the web page is opened and the server energy consumption increases a lot. Therefore, it is added when the data is stored.
So what should we do with the existing data? Now we need to perform this operation on the original data. If it is implemented by editing the data in the background one by one, even if we only need a few points, the amount of work is also very large, then we need a batch processing operation.
Write a batch processing program. After debugging and testing, the following program can replace the external links and external images in the original database.
For example, the site is http://www.ledaokj.com
A link in an article is http://www.53sj.net/article-6-1.html.
A picture is http://www.53sj.net/data/attachment/block/d3/d34780d1fca3d6b7960a7eb7a2c4c0d3.jpg
After Batch Processing
The Code becomes <a href = "http://www.53sj.net/article-6-1.html" rel = "external nofollow"
Batch filter MYSQL database internal and external links and image program code global $ config, $ db; $ SQL = "SELECT 'id ', 'content' FROM '{$ db-> prefix} article' "; $ a_list = $ db-> query ($ SQL); $ domain = $ config ['url']; $ domain = substr ($ domain, 0, strlen ($ domain)-1); // modify the current domain URL foreach ($ a_list as $) {$ content = content_nofollow ($ a ['content'], $ domain); update_a ($ a ['id'], addslashes ($ content);} exit; function update_a ($ id, $ content) {global $ config, $ db; $ SQL = "update '{$ Db-> prefix} article 'set 'content' =' {$ content} 'where 'id' = {$ id }"; if ($ db-> execute ($ SQL) {echo $ id. 'Update successful! <Br/> ';}}// add nofllow $ content to external links $ domain Current website domain name function content_nofollow ($ content, $ domain) {preg_match_all ('/href = "(. *?) "/', $ Content, $ matches); if ($ matches) {foreach ($ matches [1] as $ val) {if (strpos ($ val, $ domain) === false) $ content = str_replace ('href = "'. $ val. '"', 'href = "'. $ val. '"rel =" external nofollow "', $ content) ;}} preg_match_all ('/src =" http :(. *?) "/', $ Content, $ matches); if ($ matches) {foreach ($ matches [1] as $ val) {if (strpos ($ val, $ domain) === false) $ content = str_replace ('src = "http :'. $ val. '"', 'src =" http :'. $ val. '"rel =" external nofollow "', $ content) ;}return $ content;} original link: PHP batch filter MYSQL database out-of-site links and Images