PHP has Curl library that let’s you communicate with other servers. The Curl libaray is enabled by installing cUrl extension in PHP.INI. You just need to uncomment “extension=php_curl.dll” in PHP.INI file to install Curl library.
As a php developer, sometimes we need to get data from other server or need to make request to other server like payment gateways integration, fetching catalog etc. By using Curl library, You can make http request to a server and get the required data. you can also decode the JSON result with json_decode() function.
Here in this post, We will make a Curl request to soundcloud api to get the details of a track. The result will be a list of track details in json data format. The json_decode() function will then convert the json object into an array and will finally print out the details.
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $result = json_decode($cexecute,true);
- echo “Id: “.$result['id'];
- echo “<br>Title: “.$result['title'];
- echo “<br>Description: “.$result['description'];
Title: there might be coffee
Description: work in progress, still needs to be mixed n mastered. ill get around to it eventually