- json_decode: documentation ( source)
- var_export: documentation ( source)
<?php
$service_url = 'http://api3.wordtracker.com/search';
$curl = curl_init($service_url);
$curl_post_data = array(
'app_id' => '09d67621',
'app_key' => 'c0ab83a5057b00d294a2b7531ce21236',
'keyword' => 'cheap holidays',
'limit' => '3'
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}
echo 'response ok!';
var_export($decoded->response);
?>