Three examples of php url parsing. Method 1: Copy the code as follows: $ urlwww.baidu.com; file_get_contents ($ url); Method 2: Copy the code as follows: CURL method $ urlwww.baidu.com; $ c Method 1:
The code is as follows:
$ Url = "http://www.baidu.com ";
File_get_contents ($ url );
Method 2:
The code is as follows:
// CURL method
$ Url = "http://www.baidu.com ";
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
$ Ret = curl_exec ($ ch );
Curl_close ($ ch );
Echo $ ret;
Method 3:
The code is as follows:
$ Url = "http://www.baidu.com ";
$ Fp = fopen ($ url, "r ");
$ Response = '';
While ($ row = fgets ($ fp )){
$ Response. = trim ($ row). "\ n ";
}
Note: If the remote url cannot be called after ping, try wget.
The code is as follows:
Resolving www.xxx.com. .. 114. xxx
Connecting to www.xxx.com | 114. xxx |: 80... connected.
HTTP request sent, awaiting response... 403 Forbidden
10:58:22 ERROR 403: Forbidden.
This is not the case!
Pipeline code is as follows: $ url = "http://www.baidu.com"; file_get_contents ($ url); Method 2: code as follows: // CURL method $ url = "http://www.baidu.com"; $ c...