Home > Uncategorized > Access Tripadvisor API in PHP

Access Tripadvisor API in PHP

<?php

$url = “http://api.tripadvisor.com/api/partner/2.0/map/42.33141,-71.099396/attractions?key=xxxx&#8221;;

$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/&#8217;);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
return $output;
}
?>

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: