PHP batch delete webpage content Super-level link _ PHP Tutorial

Source: Internet
Author: User
Tags preg
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.