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"