Tech Forum, Computer Repair and Networking discussions Forum Index Tech Forum, Computer Repair and Networking discussions
Technical Information, Tech Forum and Chat
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Adding Local Weather.

 
Post new topic   Reply to topic    Tech Forum, Computer Repair and Networking discussions Forum Index -> PHP
View previous topic :: View next topic  
Author Message
admin
Site Admin


Joined: 16 May 2006
Posts: 84
Location: NJ

PostPosted: Sun Feb 18, 2007 2:30 am    Post subject: Adding Local Weather. Reply with quote

Code:


<html>
<head>
<title>City Weather</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box &#123;
        font-family: "Times New Roman", Times, serif;
        font-size: 13px;
        border: 1px ridge #999999;
        font-style: normal;
        color: #000000;
        text-decoration: none;
        background-color: #FFFFFF;
        background-image: none;
        background-position: center;
        line-height: normal;
        font-weight: bold;
}
-->
</style>
</head>

<body>
<form action="<?php echo $self ?>" method="post">
    <select id="city" name="city" size="1" class="box">
              <option <?echo $s?>>Select City</option>
              <option value="08330" <?echo $s?>>Mays Landing</option>
              <option value="08234" <?echo $s?>>Egg Harbor Township</option>
              <option value="08362" <?echo $s?>>Vineland</option>
              <option value="08401" <?echo $s?>>Atlantic City</option>
              <option value="08043" <?echo $s?>>Voorhees</option>
              <option value="08002" <?echo $s?>>Cherry Hill</option>
              <option value="11209" <?echo $s?>>Brooklyn - Bay Ridge</option>
            </select>
<input type="submit" name="submit" value="Submit">
</form>
 
<?php
if(isset($_POST['submit']))
&#123;
        $self = $_SERVER['php_self'];
        $city = $_POST['city'];

$disp_text_cond = "1";
$disp_humidity = "1";
$disp_feels_like = "1";
$disp_UV_idx = "1";
$disp_winds = "1";
$disp_baro = "1";
$disp_msn_link_text = "1";

if (!$accid) &#123;
$accid="$city";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

foreach ($WeatherFields[1] as $WeatherField) &#123;
    $FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
    preg_match($FieldSpec, $CurlContent, $WeatherData);
    $MsnWeather[$WeatherField] = $WeatherData[1];
}


$temp_f = $MsnWeather['Temp'];
$temp_c = round(($temp_f - 32)/1.8);
$temp_feels_like_f = $MsnWeather['Real'];
$temp_feels_like_c = round(($temp_feels_like_f - 32)/1.8);

print "<table class=\"box\" width=\"170\" border=\"1\" " . $MsnWeather['Acid'] . "')\">";
print "<td height=\"10\" align=\"center\" valign=\"middle\"><span class=\"txt_tbl_body3\">" . $MsnWeather['City'] ."</span></td></tr></td>";
if ($disp_text_cond == "1") &#123;
print "<tr><td height=\"15\" align =\"center\"><span class=\"txt_tbl_body3\">" . $MsnWeather['ConText'] . "</strong></span></tr></td>";
}
print "<tr><td align =\"center\"><strong><span class=\"txt_tbl_body3\">".  $temp_c."°C </span></strong><span class=\"txt_tbl_body2\">(" .$MsnWeather['Temp']  . "°F)</span></tr></td></table>";

if ($disp_humidity == "1") &#123;
print "<table class=\"box\" width=\"170\" border=\"1\">";
print "<tr><td align =\"left\"><span class=\"txt_tbl_body2\">" . "Humidity</span><td align=\"left\"><span class=\"txt_tbl_body2\"><strong>" . $MsnWeather['Humid'] . "%</span></strong></tr></td></td>";
}
if($disp_feels_like == "1") &#123;
}
if ($disp_UV_idx == "1") &#123;
print "<tr><td align =\"left\"><span class=\"txt_tbl_body2\">" . "UV Index </span><td align=\"left\"><span class=\"txt_tbl_body2\"><strong>" . $MsnWeather['UV'] . " / 10</strong></span></tr></td></td>";
}
if ($disp_winds = "1") &#123;
print "<tr><td align =\"left\"><span class=\"txt_tbl_body2\">" . "Winds  </span><td align=\"left\"><span class=\"txt_tbl_body2\"><strong>" . $MsnWeather['WindD'] . "</strong> @ <strong>". $MsnWeather['WindS'] ."</strong></span></tr></td></td>";
}
if ($disp_baro == "1") &#123;
print "<tr><td align =\"left\"><span class=\"txt_tbl_body2\">" . "Barometer </span><td align=\"left\"><span class=\"txt_tbl_body2\"><strong>" . $MsnWeather['Baro'] . " in." . "</strong></span></tr></td></td>";
}
if ($disp_msn_link_text == "1") &#123;
}
else &#123;
print "</table>";
}
}
?>
</body>
</html>
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Tech Forum, Computer Repair and Networking discussions Forum Index -> PHP All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

Googlepage: GooglePullerPage