PHP batch deletes super-level links in webpage content. During content stations, collection software is often used to attack other station resources on the Internet, and thousands of articles are collected, after the collection, some super chains of the original site often use the collection software to attack other station resources on the Internet when making content sites, collection is a collection of thousands of articles. After collection, we found that some of the original site's hyperlink in the content. if I had to modify them one by one, I had to write a method and the test was successful.
Let's briefly describe the principle. here we reuse the PHP replacement function preg_replace. In practice, we often use preg_replace to replace some dangerous characters or convert some slashes or carriage returns. Preg_replace ($1, $2, $3) has three important parameters. $1 is the string to be searched, and $2 is the string to be replaced, $3 is the string to be replaced.
Now that we know the working principle of the preg_replace function, it is not difficult to replace the hyperlink. we only need to convert the parameters $1 and $2 into arrays and replace them in batches. The following are the methods, the test is successful and shared to phper.
The code is as follows: |
|
$ Str = "hyperlink | this is a link "; Function removelink ($ str ){ $ Mode = array ("# iUs", "# iUs "); $ Want = array ("",""); $ Con = preg_replace ($ mode, $ want, $ str ); Return $ con; } Echo removelink ($ str ); ?> |
Or
The code is as follows: |
|
$ Content = file_get_contents('test.html '); $ Url = 'http: // www.hzhuti.com '; // the new url to be replaced $ Preg = '/[s] href = ("|') [S] * (" | ')/I '; $ Replace = 'href = "'. $ url .'"'; $ Content = preg_replace ($ preg, $ replace, $ content); // regular expression replacement Create_log ('newhtml ', $ content); // generate a new file ?>
|
Yes.
Some of the original site's super links found in the ghost file...