This article mainly introduces three examples of using php to parse URLs. For details, refer to 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!