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