Access Tripadvisor API in PHP
<?php
$url = “http://api.tripadvisor.com/api/partner/2.0/map/42.33141,-71.099396/attractions?key=xxxx”;
$json = HttpGet($url);
$djson = json_decode($json, true);
$htmlOut = “<ul>”;
foreach($djson[“data”] as $poi)
{
$htmlOut = $htmlOut . ‘<li><a href=”‘ . $poi[“web_url”] . ‘”>’ . $poi[“name”] . ‘</a> – ‘ . $poi[“address_obj”][“address_string”] . ‘</li>’;
}
$htmlOut = $htmlOut . ‘</ul>’;echo $htmlOut;
function HttpGet($url) {
$ch = curl_init($url );
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT,’Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13′);
curl_setopt($ch, CURLOPT_REFERER, ‘http://www.google.com/’);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
return $output;
}
?>