Skip to content

Instantly share code, notes, and snippets.

@ahgood
Created April 23, 2016 08:38
Show Gist options
  • Save ahgood/acbfccfd6f21b6dbbb0210ab69c22995 to your computer and use it in GitHub Desktop.
Save ahgood/acbfccfd6f21b6dbbb0210ab69c22995 to your computer and use it in GitHub Desktop.
<?php
$time_start = microtime(true); //record the execution time
$xml = simplexml_load_file('data.xml');
$country = '';
$city = '';
$search = '';
if (isset($_GET["search"])) {
$search = trim(htmlspecialchars($_GET["search"]));
}
if (isset($_GET["country"])) {
$country = trim(htmlspecialchars($_GET["country"]));
$country = '[Country="' . $country . '"]';
}
if (isset($_GET["city"])) {
$city = trim(htmlspecialchars($_GET["city"]));
$city = '[City="' . $city . '"]';
}
$hotels = $xml->xpath('/Root/Hotel/HotelInfo' . $country . $city);
foreach($hotels as $hotel) {
if ($search !== '') {
$hotel_str = strip_tags($hotel->asXML());
if (strpos($hotel_str, $search) !== false) {
var_dump(json_encode($hotel));
}
} else {
echo "Hotel: {$hotel->CompanyName}<br />";
}
}
echo '<br />Total execution time in seconds: ' . (microtime(true) - $time_start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment