2 $location = isset($_GET['location']) ? $_GET['location'] : '02135';
4 //get xml from google api
6 curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/ig/api?weather='. $location);
7 curl_setopt($ch, CURLOPT_HEADER, 0);
8 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
9 curl_setopt($ch, CURLOPT_TIMEOUT, 10);
10 $result = curl_exec($ch);
13 //parse xml (thx KomunitasWeb.com for pointers)
14 $xml = simplexml_load_string($result);
15 $information = $xml->xpath("/xml_api_reply/weather/forecast_information");
16 $current = $xml->xpath("/xml_api_reply/weather/current_conditions");
17 $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
22 <meta charset="utf-8">
23 <meta name="viewport" content="width=device-width, initial-scale=1">
24 <title>jQuery Mobile Framework - Weather for <?php echo $information[0]->city['data']; ?></title>
25 <link rel="stylesheet" href="../../css/themes/default/" />
26 <script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
27 <script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
29 .current { text-align: left; }
30 h1 { font-size: 1.3em; text-align: center; }
31 .ui-listview img { left: auto; margin: 10px; position: absolute; right: 10px; }
32 .current { position: relative; }
33 .current img { float: left; margin: 5px 10px 0 0; }
34 .current p { font-weight: bold; font-size: 1.1em; margin-left: 20px; }
35 .ui-mobile label { position: absolute; left: -9999px; }
36 .ui-input-search, .min-width-480px .ui-input-search { margin: 5px auto; width: auto; float: none; display: block; }
39 $('div').live('pagecreate',function(){
40 $('.ui-listview img').removeClass('ui-corner-bl');
46 <div data-role="page" data-theme="a">
48 <form action="" method="get" class="ui-body ui-body-a ">
49 <label for="location">Change zip code:</label>
50 <input type="search" name="location" id="location" value="<?php echo$location; ?>" placeholder="zip code..." data-theme="a" />
51 <input type="submit" data-role="nojs" value="submit" />
55 <div data-role="content">
56 <h1>Currently in <?=$information[0]->city['data']; ?>:</h1>
57 <div class="current ui-body ui-bar-a ui-corner-all">
59 <img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather">
61 <?php echo $current[0]->temp_f['data']; ?>° F,
62 <?php echo $current[0]->condition['data']; ?>
68 <ul data-role="listview" data-inset="true" data-theme="a">
69 <li data-role="list-divider">This week's forecast</li>
70 <?php foreach ($forecast_list as $forecast) : ?>
73 <img src="<?php echo 'http://www.google.com' . $forecast->icon['data']; ?>">
74 <h3><?php echo $forecast->day_of_week['data']; ?></h3>
76 <?php echo $forecast->low['data']; ?>° F - <?php echo $forecast->high['data']; ?>° F,
77 <?php echo $forecast->condition['data']; ?>