kfranck
asked on
Using ASP, how can I code weather for my site?
I have an ASP project that I want to add current temperature (Fahrenheit) and current conditions (cloudy, sunny, rain, etc.) to my Web site. I know there are a lot of weather widgets available by google search, but I am looking for ASP code that will allow me to display this information in a small place. The NOAA weather code I am interested in is KTDZ.
With the help of and Experts Exchange expert, I have the code for PHP. But the server for my Web site is ASP.
Any suggestions on how to do this? I have attached the PHP code for what I am looking (I can find a converter that works correctly;.)
With the help of and Experts Exchange expert, I have the code for PHP. But the server for my Web site is ASP.
Any suggestions on how to do this? I have attached the PHP code for what I am looking (I can find a converter that works correctly;.)
<?php // RAY_temp_kfranck.php
error_reporting(E_ALL);
// DEMONSTRATE A WEATHER WIDGET USING IGOOGLE API
date_default_timezone_set('America/New_York');
$url = 'http://www.google.com/ig/api?weather=toledo,oh';
$xml = file_get_contents($url);
$obj = SimpleXML_Load_String($xml);
// ACTIVATE THIS TO SEE THE OBJECT
// echo "<pre>";
// var_dump($obj);
// echo "</pre>";
// EXTRACT AND FORMAT THE DATA
$c = $obj->weather->forecast_information->city["data"];
$d = $obj->weather->forecast_information->current_date_time["data"];
$d = date('g:ia', strtotime($d));
$s = $obj->weather->current_conditions->condition["data"];
$f = $obj->weather->current_conditions->temp_f["data"];
// THE FINISHED HTML TAG WE WANT
$w = "<span id=\"weather\">$s and $f° at $d in $c</span>" . PHP_EOL;
// THE HTML STRING IN HEREDOC NOTATION
$html = <<<ENDHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
$w
</body>
</html>
ENDHTML;
// WRITE THE STRING TO THE BROWSER
echo $html;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER