PHP头条
热点:

借用GoogleAPI写一个查看天气预报的类-PHP源码


php代码

forecast_information->city;
  if (isset ( $xml ['weather']->problem_cause )) {
   $problem = ( array ) $xml ['weather']->problem_cause;
   echo $problem ['@attributes'] ['data'];
   return;
  }
  
  $conditions = ( array ) $xml ['weather']->current_conditions->condition;
  $humidity = ( array ) $xml ['weather']->current_conditions->humidity;
  $temp_c = ( array ) $xml ['weather']->current_conditions->temp_c;
  $conditions_icon = ( array ) $xml ['weather']->current_conditions->icon;
  $wind_condition = ( array ) $xml ['weather']->current_conditions->wind_condition;
  $forecast = ( array ) $xml ['weather'];
  $forecast = ( array ) $forecast ['forecast_conditions'];
  $html = '';
  foreach ( $forecast as $key => $val ) {
   
   ${'day_of_week_' . $key} = ( array ) $val->day_of_week;
   ${'low_' . $key} = ( array ) $val->low;
   ${'high_' . $key} = ( array ) $val->high;
   ${'icon_' . $key} = ( array ) $val->icon;
   ${'condition_' . $key} = ( array ) $val->condition;
   $html .= "

{${'day_of_week_'.$key}['@attributes']['data']}        http://www.google.com{${'icon_'.$key}['@attributes']['data']}\ " width=40 height=40>

        {${'low_'.$key}['@attributes']['data']}°C | {${'high_'.$key}['@attributes']['data']}°C
";
  
  }
  self::printCss ();
  echo <<   

  
{$city['@attributes']['data']}  

    

      
http://www.google.com{$conditions_icon['@attributes']['data' ]}" width=40 height=40>

      

      
{$temp_c['@attributes']['data']}°C

      
当前: {$conditions['@attributes']['data']}

        {$wind_condition['@attributes']['data']}

        {$humidity['@attributes']['data']}

    

    

 $html
    

  



weather;
 
 }
 /**
  * 打印样式
  */
 static public function printCss() {
  echo << 

css;
 }
 /**
  * 创建xml缓存
  * @param $contents 要缓存的内容
  */
 static private function cacheXML($contents) {
  $contents = str_ireplace ( '', " \n", $contents );
  $contents = mb_convert_encoding ( $contents, 'utf-8', 'gbk' );
  file_put_contents ( self::$weatherXML, $contents ) or die ( '没有写权限' );
 }
}
weather::getXML ();
weather::analysisXML ();
?>

www.phpzy.comtrue/phpyy/42407.htmlTechArticle借用GoogleAPI写一个查看天气预报的类-PHP源码 php代码 forecast_information->city; if (isset ( $xml [weather]->problem_cause )) { $problem = ( array ) $xml [weather]->problem_cause; echo $problem [@attributes] [data]; return;...

相关文章

PHP之友评论

今天推荐