Weather script for those who been looking for

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Weather script for those who been looking for

    ok i make a simple script to get weather, all free to mod it but give credits. no need to pay $10 to anybody

    Code:
    <html>
    <head>
    <title>Simple Weather Search</title>
    <style type="text/css">
    body{
    background:#444446;
    color:red;
    }
    img {
    border:1px solid #ffffff;
    float:left;
    }
    h1 {
    text-align:center;
    color:#FE5539;
    font-size:18px;
    }
    #head {
    background:#646466;
    margin: 0 auto;
    border:solid 1px #ffffff;
    width:300px;
    height:auto;
    }
    #content{
    background:#A4A4A7;
    color:#ffffff;
    font-size:16px;
    font-weight:bold;
    margin: 0 auto;
    height:52px;
    width:300px;
    border:solid 1px #ffffff;
    }
    #foot {
    background:#646466;
    border:solid 1px #ffffff;
    width:300px;
    height:auto;
    margin: 0 auto;
    }
    #foot input{
    background:#FE5539;
    border:solid 1px #ffffff;
    }
    </style>
    </head>
    <body>
    <?php
    if(isset($_POST['submit']))
    {
    $placename = $_POST['city_town_name']; 
    $lang = 'en';
    $place=urlencode($placename);
    $place = utf8_encode($place);
    $url = 'http://www.google.com/ig/api?weather='.$place.',$&hl='.$lang.'';
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
    $raw_data = curl_exec ($ch);
    curl_close ($ch);
    $xml = simplexml_load_string($raw_data);
    $condition = $xml->weather->current_conditions->condition['data'];
    $temp_c = $xml->weather->current_conditions->temp_c['data'];
    $humidity = $xml->weather->current_conditions->humidity['data'];
    $icon = $xml->weather->current_conditions->icon['data'];
    echo ("<div id='head'><h1>Results for $placename</h1></div>");
    for ($i = 0; $i < count($xml->weather->forecast_conditions); $i++){
    $data = $xml->weather->forecast_conditions[$i];
    $day_of_week = $data->day_of_week['data'];
    $low = $data->low['data'];
    $high = $data->high['data'];
    $condition = $data->condition['data'];
    $day_of_week = utf8_decode($day_of_week);
    $img = 'http://www.google.com/' . $data->icon['data'];
    echo ("
    <div id='content'>
    <img align=\left\" src=\"$img\" width=\"50\" height=\"50\"/>
    $day_of_week / $low&#176;|$high&#176; / $condition<br/><br/>
    </div>
    ");
    }
    }
    ?>
    <div id='foot'>
    <form action='weather.php' method='POST'/>
    <p align='center'>
    <input name='city_town_name' type='text' value=''/><br/>
    <input type='submit' name='submit' value='get weather'/>
    </form>
    </p>
    <p align='center'><small>&#169; i_love_php_mysql from coading-talk.com</small></p>
    </div>
    </body>
    </html>
    sorry i post in wrong section, mods please shift it
    Last edited by i_love_php_mysql; 05.10.10, 14:19.
Working...
X