Replace the obtained URL in the source code.

Source: Internet
Author: User
Replace the obtained URL in the source code! $ Url & nbsp; www.baidu.com; $ newurl & nbsp; www.163.com; $ contents & nbsp; file_get_contents ($ url); echo & nbsp; preg_replace (href replaces the obtained URL in the source code!
$ Url = "http://www.baidu.com ";
$ Newurl = "http://www.163.com ";

$ Contents = file_get_contents ($ url );
Echo preg_replace ('/href = "(. + ?) "/I ', 'href =" http: //'. rand (100,999). '"', $ contents );

I originally wanted to randomly replace all connections in the source code. now all connections are replaced with a random one! How can this problem be solved?


------ Solution --------------------
$ Contents = <TXT
Href = "http://www.baidu.com"
Href = "http://www.163.com"
TXT;

Echo preg_replace ('/href = "(. + ?) "/Ise ','" href = \ "http: //". rand (100,999). "\" "', $ contents );
Href = "http:/// 217"
Href = "http:/// 562"

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.