cURL error number:" .curl_errno($ch);
echo "
cURL error:" . curl_error($ch);
exit;
}
# don't let this script run for more than 60 seconds
set_time_limit(60);
# create file handles if needed
if (!defined('STDIN'))
{
define('STDIN', fopen('php://stdin', 'r'));
}
if (!defined('STDOUT'))
{
define('STDOUT', fopen('php://stdout', 'w'));
}
if (!defined('STDERR'))
{
define('STDERR', fopen('php://stderr', 'w'));
}
# retrieve this web page
# get_contents no longer allowed, uses curl above.
# $weatherPage=file_get_contents($weatherURL);
# get temperature in Fahrenheit
if (preg_match("/([0-9.]+)<\/temp_f>/i",$weatherPage,$matches))
{$currentTemp=$matches[1];}
# echo ($currentTemp);
echo "\n";
echo 'Tucson Weather Forecast';
echo "\n";
echo "\n";
echo 'Temperature ' ;
echo ($currentTemp);
echo ' degrees F';
echo "\n";
# get wind direction
if (preg_match("/North<\/wind_dir>/i",$weatherPage))
{
$currentWindDirection='North';
}
elseif (preg_match("/South<\/wind_dir>/i",$weatherPage))
{
$currentWindDirection='South';
}
elseif (preg_match("/East<\/wind_dir>/i",$weatherPage))
{
$currentWindDirection='East';
}
elseif (preg_match("/West<\/wind_dir>/i",$weatherPage))
{
$currentWindDirection='West';
}
elseif (preg_match("/Northwest<\/wind_dir>/i",$weatherPage))
{
$currentWindDirection='Northwest';
}
elseif (preg_match("/Northeast<\/wind_dir>/i",$weatherPage))
{
$currentWindDirection='Northeast';
}
elseif (preg_match("/Southwest<\/wind_dir>/i",$weatherPage))
{
$currentWindDirection='Southwest';
}
elseif (preg_match("/Southeast<\/wind_dir>/i",$weatherPage))
{
$currentWindDirection='Southeast';
}
# echo ($currentWindDirection);
# get wind speed
if
(preg_match("/([0-9]+)([\.]+)([0-9]+)<\/wind_mph>/i",$weatherPage,$matches))
{
$currentWindSpeed = $matches[1];
}
# echo ($currentWindSpeed);
if ($currentWindDirection && $currentWindSpeed)
{
echo 'Wind from the ';
echo ($currentWindDirection);
echo ' at ' ;
echo ($currentWindSpeed);
echo ' MPH';
echo "\n";
}
# get relative humidity
if (preg_match("/([0-9.]+)<\/relative_humidity>/i",$weatherPage,$matches))
{$currentHumidity=$matches[1];}
# echo ($currentHumidity);
echo "" ;
echo 'Humidity ' ;
echo ($currentHumidity);
echo "%";
echo "\n";
# get visibility in miles
if (preg_match("/([0-9.]+)<\/visibility_mi>/i",$weatherPage,$matches))
{$currentVisibility=$matches[1];}
# echo ($currentVisibility);
echo "" ;
echo 'Visibility ' ;
echo ($currentVisibility);
echo ' miles';
echo "\n";
# get barometric pressure
If
(preg_match("/([0-9]+)([\.]+)([0-9]+)<\/pressure_in>/i",$weatherPage,$matches))
{
$currentPressure1 = $matches[1];
$currentPressure2 = $matches[3];
}
# echo ($currentPressure1.$currentPressure2);
echo 'Barometric pressure ' ;
echo ($currentPressure1);
echo ".";
echo ($currentPressure2);
echo ' in';
echo "\n";
?>