Four Methods for PHP to call remote URLs

Source: Internet
Author: User

Introduction: This is a detailed page for PHP to call remote URLs. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 329765 'rolling = 'no'>
1. Use file_get_contents to get the content in get mode.

Example:

 
$ Html = file_get_contents ($ URL );

2. Use fopen to open the URL and get the content

Example:

 
$ Fp = fopen ($ URL, 'R'); $ html = stream_get_meta_data ($ FP );

3. Use the file_get_contents function to obtain the URL in post mode.

$ DATA = array ('test' => 'hellword'); $ DATA = http_build_query ($ data ); $ opts = array ('http' => array ('method' => 'post', 'header' => "Content-Type: application/X-WWW-form-urlencoded \ r \ n ". "Content-Length :". strlen ($ data ). "\ r \ n", 'content' => $ data),); $ context = stream_context_create ($ opts); $ html = file_get_contents ($ URL, false, $ context );

4. Before using the curl library, make sure that curl extension is enabled.

 
$ CH = curl_init (); $ timeout = 5; curl_setopt ($ ch, curlopt_url, $ URL); curl_setopt ($ ch, success, 1); curl_setopt ($ ch, curlopt_connecttimeout, $ timeout); $ file_contents = curl_exec ($ ch); curl_close ($ ch); echo $ file_contents;

More articles on "four methods for PHP to call remote URLs"

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/329765.html pageno: 12.

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.