1

I am retrieving Google Weather XML as such:

<?php
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=LONDON&hl=en-GB');
?>

Is it possible to set the city from an input? As a search box. So you can search which city you are pulling plus the language. I don't mind you search the language as en-GB, US and such instead of english, french etc because I will be adding a selectbox later on.

For example: http://jsfiddle.net/7WFGz/

Thanks alot

jQuerybeast
  • 14,130
  • 38
  • 118
  • 196

1 Answers1

1

The simplest solution:

Your form from jsfiddle

<form action="weather.php" method="get">
    <input type="search" placeholder="City" name="city">
    <input type="search" placeholder="Language" name="lang">
    <input type="button" value="search" style="width:100px">
</form>

weather.php file

<?php
$default_city = "LONDON";
$default_lang = "en-GB";
$city = (iseet($_GET['city']) AND strlen($_GET['city']) > 0) ? $_GET['city'] : $default_city;
$lang = (iseet($_GET['lang']) AND strlen($_GET['lang']) > 0) ? $_GET['lang'] : $default_lang;
// also you can (must) check input data like a preg_match('/([a-z]{2})|([a-z]{2})-([a-z]{2})/i')
$xml = simplexml_load_file('http://www.google.com/ig/api?weather='.$city.'&hl='.$lang);
atma
  • 875
  • 7
  • 10
  • Hi. Thanks for you answer. the php content is in the actually index. (index.php). What shall I turn the action=weather.php to? – jQuerybeast Sep 05 '11 at 01:31
  • No, you just need to use your actual form handler - index.php in this case. If all (form and handler) located in index.php you also can improve the form fields with something like `` - if something already submitted this value will be in field, otherwise placeholder – atma Sep 05 '11 at 02:05
  • Giving it a try in a minute. Thanks alot – jQuerybeast Sep 05 '11 at 02:39