I have trouble understanding how put out a single item from JSON api-
PHP / Json - how do I get to print a single line of data for example just route_type_name":"Train" a working demo is here- https://melbtrip.com/maps/ivanhoe.php
Thank you
Matthew
<?php
$key = ""; // supplied by PTV
$developerId = ; // supplied by PTV
$date = gmdate('Y-m-d\TH:i:s\Z');
//$nearmeurl = "/v3/stops/1071/route_type/0";
$nearmeurl = "/v3/route_types";
?>
<h1>Near Me</h1>
<?
$signedUrl = generateURLWithDevIDAndKey($nearmeurl, $developerId, $key);
drawResponse($signedUrl);
?>
<?
//$signedUrl = generateURLWithDevIDAndKey($specificurl, $developerId, $key);
//drawResponse($signedUrl);
function generateURLWithDevIDAndKey($apiEndpoint, $developerId, $key)
{
// append developer ID to API endpoint URL
if (strpos($apiEndpoint, '?') > 0)
{
$apiEndpoint .= "&";
}
else
{
$apiEndpoint .= "?";
}
$apiEndpoint .= "devid=" . $developerId;
// hash the endpoint URL
$signature = strtoupper(hash_hmac("sha1", $apiEndpoint, $key, false));
// add API endpoint, base URL and signature together
return "http://timetableapi.ptv.vic.gov.au" . $apiEndpoint . "&signature=" . $signature;
}
function drawResponse($signedUrl)
{
// echo "<p>$signedUrl</p>";//
//echo "<textarea rows=\"40\" cols=\"40\">";
echo "<textarea>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $signedUrl);
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $xmlstr = curl_exec($ch);
curl_close($ch);
echo "</textarea>";
}
?>