Adds filtering of external links to the 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 you need to perform this operation on the original data. If you want to edit the data in the background
Adds filtering of external links to the 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 you need to perform this operation on the original data. If you want to edit the data in the background
Adds filtering of external links to the 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.68idc.cn/help/uploads/allimg/150923/0I201BZ-0.jpg
After Batch Processing
The Code becomes
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!
';}
}
// 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;
}
PHP batch filter MYSQL database out-of-site links and Images