You can refer to the following methods:
Method 1: file_get_contents acquisition
lt; span style="white-space: pre"gt;?lt; /spangt;$url="/";
lt;span style="white-space:pre"gt;?lt;/spangt;$fh= file_get_contents
(' /news/fzfj/');lt;span style="white-space:pre"gt;?lt;/spangt;echo $fh;
Method 2: Use fopen to obtain the web page source code p>
lt;span style="white-space:pre"gt;?lt;/spangt;$url="/";
lt;span style="white-space:pre" "gt;?lt;/spangt;$handle = fopen ($url, "rb");
lt;span style="white-space:pre"gt;?lt;/spangt;$ contents = "";
lt; span style="white-space: pre"gt;?lt;/spangt; while (!feof($handle)) {
lt ;span style="white-space:pre"gt;?lt;/spangt;$contents .= fread($handle, 8192);
lt;span style="white-space:pre" gt;?lt;/spangt;}
lt;span style="white-space:pre"gt;?lt;/spangt;fclose($handle);
lt ;span style="white-space:pre"gt;?lt;/spangt;echo $contents; //Output the obtained content.
Method 3: Use CURL to obtain the web page source code
$url="/";
$UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$curl = curl_init();?//Create a new CURL resource
curl_setopt($curl, CURLOPT_URL, $url);?//Set the URL and corresponding options
curl_setopt($curl, CURLOPT_HEADER, 0);? //0 means not to output Header, 1 means output
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);? //Set whether to display header information, 1 Display, 0 does not display. //If successful, only the result will be returned and nothing will be automatically output.
Returns FALSE if failed
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_ENCODING, '');?//Set the encoding format, empty means all formats of encoding are supported
//The content of the "Accept-Encoding:" part of the header, the supported encoding format is: "identity ", "deflate", "gzip". ?
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
//Set this option to a A header with a non-zero value (like "Location: ") will be sent by the server as part of the HTTP header (note that this is recursive, PHP will send a header of the form "Location: ").
$data = curl_exec($curl);
echo $data;
//echo curl_errno($curl); //Return 0 to indicate the program Successful execution
curl_close($curl);?//Close cURL resources and release system resources
PHP (foreign name: PHP: Hypertext Preprocessor, Chinese name: "Hypertext Preprocessor" "Processor") is a general-purpose open source scripting language. The syntax absorbs the characteristics of C language, Java and Perl, which is easy to learn and widely used. It is mainly suitable for the field of Web development. PHP's unique syntax mixes C, Java, Perl, and PHP's own syntax. It can execute dynamic web pages faster than CGI or Perl.
Compared with other programming languages, dynamic pages made with PHP embed the program into the HTML (an application under the standard universal markup language) document for execution, and the execution efficiency is higher than that of completely generating HTML. The marked CGI is much higher; PHP can also execute compiled code, and the compilation can achieve encryption and optimize code running, making the code run faster.
Reference material: PHP (hypertext preprocessor)-Baidu Encyclopedia