What is curl in PHP?

PHP supports libcurl,that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols.

<?php 
// create a new cURL resource 
$ch = curl_init(); 
// set URL and other appropriate options 
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
// Execute the given cURL session. 
$result = curl_exec($ch); 
// close cURL resource, and free up system resources 
curl_close($ch); 
?>

Find nearest locations using Google Place API.

<?php 
$ch = curl_init();
 $lat = "-33.8670522";
 $long= "151.1957362";
 $radius = "500";
 $apiKey = "YOUR_API_KEY"; 
$url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$lat,$long&radius=$radius&types=food&key=$apiKey";
 //set URL and other appropriate options 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_exec($ch); curl_close($ch);
 ?>

Leave a Reply