Files
web-development/zoesch.de/test/wetter.php
Felix Zösch 07c290a453 Initial commit: Backup der Webseiten
- zoesch.de
- blitzkiste.net
- gruene-hassberge (norbert.zoesch.de)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-13 01:17:15 +01:00

125 lines
4.4 KiB
PHP

<?php
$key = 'edadb0fb1e616271';
$error = '';
$weather = '';
$city = $_GET['city'];
$city_string = file_get_contents("http://autocomplete.wunderground.com/aq?query=${city}");
$parsed_city = json_decode($city_string, true);
$city_code = $parsed_city['RESULTS'][0]['l'];
foreach ($parsed_city['RESULTS'] as $value) {
echo '<a href="'.$value['l'].'">'.$value['name'].'</a><br>';
}
$json_string = file_get_contents("http://api.wunderground.com/api/${key}/geolookup/conditions/lang:DL/q/${city_code}.json");
$parsed_json = json_decode($json_string);
$location = $parsed_json->{'location'}->{'city'};
$country = $parsed_json->{'location'}->{'country_iso3166'};
$weatherText = $parsed_json->{'current_observation'}->{'weather'};
$temp_c = $parsed_json->{'current_observation'}->{'temp_c'};
$humidity = $parsed_json->{'current_observation'}->{'relative_humidity'};
$icon = $parsed_json->{'current_observation'}->{'icon'};
$icon_img = '<img src="http://icons.wxug.com/i/c/i/'.$icon.'.gif" alt="Weather Icon" style="width:50px;height:50px";>';
if ($location) {
$weather = "Aktuelles Wetter in ${location}, ${country}:<br> ${icon_img} <br> ${weatherText}<br> Temperatur: ${temp_c}&degC<br> Luftfeuchtigkeit: ${humidity}";
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Wetter</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Unterstützung für Media Queries und HTML5-Elemente in IE8 über HTML5 shim und Respond.js -->
<!-- ACHTUNG: Respond.js funktioniert nicht, wenn du die Seite über file:// aufrufst -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
body {
background: url(img/sky.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.wetter {
margin-top: 300px;
text-align: center;
max-width: 1170px;
}
form {
max-width: 500px;
margin-right: auto;
margin-left: auto;
}
</style>
</head>
<body>
<div class="container-fluid wetter">
<div class="row">
<div class="col-md-12">
<h1>Wetter</h1>
<form>
<div class="form-group">
<label for="stadt">Stadt eingeben:</label>
<input type="text" class="form-control" id="city" name="city" placeholder="Berlin, Tokyo, Paris, London">
</div>
<button type="submit" class="btn btn-default">Los!</button>
</form>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Bitte Stadt wählen
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#">Aktion</a></li>
<li><a href="#">Andere Aktion</a></li>
<li><a href="#">Irgendwas anderes</a></li>
<li><a href="#">Abgetrennter Link</a></li>
</ul>
</div>
<?php
if ($weather) {
echo '<div class="alert alert-success" role="alert">'.$weather.'</div>';
} elseif ($error) {
echo '<div class="alert alert-danger" role="alert">'.$error.'</div>';
}
?>
</div>
</div>
</div>
<!-- jQuery (wird für Bootstrap JavaScript-Plugins benötigt) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>