Location: PHPKode > scripts > Free Yahoo Weather API Fetcher > free-yahoo-weather-api-fetcher/index.php
<?php
/************* Weather *****************************/
/*
Released by AwesomePHP.com, under the GPL License, a
copy of it should be attached to the zip file, or
you can view it on http://AwesomePHP.com/gpl.txt
*/
/************* Weather *****************************/

// Use Database?
$USE_DATA = true;


// Search zipcode
if($_GET['zipcode2'] != NULL){
	$zip_code = $_GET['zipcode2'];
} else {
	$zip_code = $_GET['zipcode'];
}

if($USE_DATA){
	// Include database
	include_once('database.php');
} else {
	// Include state List
	include_once('state_list.php');
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Weather API Script - Free PHP Script</title>
</head>
<body>
<form name="reload" id="reload" method="get" action="<?=$_SERVER['PHP_SELF'];?>" style="display:inline;">
  <table width="790"  border="1" align="center" cellpadding="3" cellspacing="2" bordercolor="#990000">
    <tr>
      <td bgcolor="#FFE6E6"><div align="center"><strong>Please select city: </strong></div></td>
    </tr>
    <tr>
      <td><div align="center">
        <select name="state" id="state">
		<option value=""></option>
		<?=$state_list_form;?>
        </select>
		<?php
		if($_GET['state'] != NULL){
		?>
        <select name="zipcode" id="zipcode">
		<option value=""></option>
		<?=$city_list_form;?>
        </select>
		<?php } ?>
		<br/>
or Enter ZipCode: 
<input name="zipcode2" type="text" id="zipcode2" value="<?=$zip_code;?>">
 <input type="submit" name="Submit" value="Submit">
      </div></td>
    </tr>
	<?php
	if($zip_code != NULL){
	
		// Get weather info
		$f = fopen('http://weather.yahooapis.com/forecastrss?p='.$state_code,'r');
		while($t = fread($f,102465)){ $content .= $t; }
		fclose($f);
		preg_match('/<img src="(.*)"\/>/Usm',$content,$results); $image = $results[1];
		preg_match('/Current Conditions:<\/b><br \/>(.*)<BR \/>/Uism',$content,$results); $cur_conditions = $results[1];
		preg_match('/Forecast:<\/b><BR \/>(.*)<br \/>/ism',$content,$results); $forecast = $results[1];
		unset($content);
	?>
    <tr>
      <td bgcolor="#FFE6E6"><div align="center"><strong>Weather for <?=$cityname;?>, <?=$state_name;?> <?=$zip_code;?>: </strong></div></td>
    </tr>
    <tr>
      <td>
	  <img src="<?=$image;?>"/><br/><br/>
      <strong>Current Conditions:</strong><br/>
      <?=$cur_conditions;?><br/><br/>
      <strong>Forecast:</strong><br/>
      <?=$forecast;?></td>
    </tr>
	<?php } ?>
  </table>
</form>
<!--
/************* Weather *****************************/
/*
Released by AwesomePHP.com, under the GPL License, a
copy of it should be attached to the zip file, or
you can view it on http://AwesomePHP.com/gpl.txt
*/
/************* Weather *****************************/
-->
</body>
</html>
Return current item: Free Yahoo Weather API Fetcher