Ec (2); & nbsp; copy the code functiongetsourcecode ($ q) {& nbsp; return @ file_get_contents ($ q );} use curl to obtain the website source file functionc_getpagecode ($ c_url, $ p_i0) {& nbsp; $ user_agent & quot script ec (2); script
The Code is as follows: |
|
Function getsourcecode ($ q ){ Return @ file_get_contents ($ q ); } // Use curl to obtain the website source file Function c_getpagecode ($ c_url, $ p_ I = 0 ){ $ User_agent = "mozilla/4.0 "; $ Proxy [0] = "http: // 211.155.231.208: 80"; // Hangzhou Telecom idc data center, Zhejiang Province $ Proxy [1] = "http: // 210.51.10.197: 8888"; // idc of Beijing tongtai tower Netcom $ Ch = curl_init (); Curl_setopt ($ ch, curlopt_proxy, $ proxy [$ p_ I]); Curl_setopt ($ ch, curlopt_url, $ c_url ); Curl_setopt ($ ch, curlopt_useragent, $ user_agent ); // Curl_setopt ($ ch, curlopt_cookiejar, "c: cookie.txt "); Curl_setopt ($ ch, curlopt_header, 0 ); Curl_setopt ($ ch, curlopt_returntransfer, 1 ); Curl_setopt ($ ch, curlopt_followlocation, 1 ); Curl_setopt ($ ch, curlopt_timeout, 120 ); $ Result = curl_exec ($ ch ); Curl_close ($ ch ); Return $ result; } |
// Instance application
The Code is as follows: |
|
$ Url = 'HTTP: // mb.111cn.net '; // $ Body = getsourcecode ($ url ); |
// Echo $ body; // collect all the content of mb.111cn.net to the local device.
// Take a look at the function instance for getting the website source code file with curl.
Echo c_getpagecode ($ url );