PHP and Curl

Source: Internet
Author: User

CURL PHP API comes with a wide array of options and features. This allows users to fine tune the requests and the "the" that the responses is handled.

The PHP CURL API offers a wide range of options and features to help users process requests and other information.

Step at a Glance

Initialize curl-> setup options, execute curl-> Close curl

Initialize

$ch = Curl_init ();

Set Options

curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_url, true);

Execute

Curl_exec ($ch);

Close

Curl_close ($ch);

and file_get_contents

Earlier in this chapter it is shown how to access the Yahoo spelling service with
The File_get_contents function. The following code shows how to does the same with CURL. As you'll notice, the code is a bit lengthier than the equivalent
File_get_contents version. Obviously, the the cost for you has to pay in exchange of the customizability of CURL. However, you'll soon realize that the increased number of lines are negligible in comparison to what's can do with CURL .

As with file_get_contents, the code for Curl will be longer if the same functionality is achieved. This is the price we have to pay to complicate the processing of data. However, you will soon find that the amount of code added is insignificant relative to your work.

<?php/*//yahoo Weather web service$url= ' http://api.wooyun.org/domain/cnpc.com '; $xml = file_get_contents ($url); $ Out=json_decode ($xml);p rint_r ($out); */$url = ' http://api.wooyun.org/domain/cnpc.com '; $ch =curl_init (); curl_setopt ($ch, Curlopt_url, $url);//can accept the return value curl_setopt ($ch, curlopt_returntransfer,1); $res =json_decode (Curl_exec ($ch)); Curl_close ($ch);p rint_r ($res);? >

PHP and Curl

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.