Created
February 12, 2018 10:23
-
-
Save hbcruoma/41d167a781c4578e665af6f296d1bbac to your computer and use it in GitHub Desktop.
Pikku PHP-pätkä Amican ruokalistan lukemiseen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dayname = array("", "Ma", "Ti", "Ke", "To", "Pe", "La", "Su"); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<?php | |
$ch = curl_init(); | |
//Set the URL that you want to GET by using the CURLOPT_URL option. | |
curl_setopt($ch, CURLOPT_URL, 'http://www.amica.fi/modules/json/json/Index?costNumber=0083&language=fi'); | |
//Set CURLOPT_RETURNTRANSFER so that the content is returned as a variable. | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
//Set CURLOPT_FOLLOWLOCATION to true to follow redirects. | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
//Execute the request. | |
$data = curl_exec($ch); | |
//Close the cURL handle. | |
curl_close($ch); | |
//Print the data out onto the page. | |
//echo $data; | |
$dataobj = json_decode($data); | |
//var_dump($dataobj); | |
//echo prettyPrint($data); | |
$now = (new DateTime)->setTime(0, 0, 0); | |
//var_dump($now); | |
echo "<h1>".$dataobj->RestaurantName."</h1>"; | |
foreach ($dataobj->MenusForDays as $daily) { | |
$day = new DateTime($daily->Date); | |
if (empty($daily->SetMenus)) { | |
continue; | |
} | |
$dayofweek = date('N', $day->getTimestamp()); | |
echo "<h2>".$dayname[$dayofweek]." ".$day->format('j.n.Y')."</h2>"; | |
echo "<h3>".$daily->LunchTime."</h3>"; | |
if ($day == $now) { | |
echo "<p>Tänään</p>"; | |
} | |
echo "<table border>"; | |
echo "<tr><th>Linja</th><th>Ruokalaji</th></tr>"; | |
foreach ($daily->SetMenus as $menu) { | |
if (!empty($menu->Components)) { | |
echo "<tr>"; | |
echo "<td>" . $menu->Name . "</td>"; | |
echo "<td>"; | |
foreach ($menu->Components as $component) { | |
echo $component . "<br>"; | |
} | |
echo "</td>"; | |
echo "</tr>"; | |
} | |
} | |
echo "</table>"; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment