I’m new to PHP and am doing my best to learn it. Any help is GREATLY appreciated and if you can explain in detail that’s even better!
My goal is to change my site based upon the weather condition. I found this code on [url]http://css-tricks.com/using-weather-data-to-change-your-websites-apperance-through-php-and-css/
[code=php] <?php
/* get the weather from Yahoo */
$data = get_data(“http://weather.yahooapis.com/forecastrss?p=97211&u=f”);
$weather = format_result(get_match(‘/<yweather:condition text=”(.*)”/isU’,$data));
/* debug */
//echo ‘<pre style=”background:#fff;font-size:12px;”>[‘; print_r($weather); echo ‘]</pre>’;
/* format the result */
function format_result($input)
{
return strtolower(str_replace(array(‘ ‘, ‘(‘, ‘)’), array(‘-‘, ‘-‘, ”), $input));
}
/* helper: does regex */
function get_match($regex,$content)
{
preg_match($regex,$content,$matches);
return $matches[1];
}
/* gets the xml data from Alexa */
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$xml = curl_exec($ch);
curl_close($ch);
return $xml;
}
?>
<?php Echo(“$weather”); ?>