Three examples of url parsing in php: php instances

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.