plugins:worldweather:worldweather_code

wolrdweather/makexml.php

情報読み取り部分のソースコード

<?php
/*--- Begin function --*/
function worldweather_makeXml($cityFile){
 
$myStatus=0;
$myDay=0;
if (($fHandle=fopen($cityFile,'r'))!=False)
  while (!feof($fHandle))
  {
  $buff=trim(fgets($fHandle,1024));
  switch ($myStatus){
  case 0: //seeking issue time
    if (($i=strpos($buff,'<I>Issued at',0))===False
        &&($i=strpos($buff,'<i>Issued at',0))===False) break;
    $issueTime=trim(fgets($fHandle,1024));
    $myStatus++;
    break;
  case 1: //seeking issue day
    if ($buff=='' || (!(strpos($buff,'(Local time)',0)===False)) ) break;
    $issueDay=$buff;
    $myStatus++;
    break;
  case 2: //seeking issue month
    $issueMonth=$buff;
    $myStatus++;
    break;
  case 3: //seeking issue year
    $issueYear=$buff;
    $myStatus=10;
    break;
  case 10: //seeking next day
    if (strpos($buff,'<td width="70" align="center">')===False
        && strpos($buff,'<td style="width:70;text-align:center;">')===False) break;
    $myStatus++;
    //break;
  case 11: //seeking day month
    if (($i=strpos($buff,'>',0))===False) break;
    $fDay[$myDay]=trim(substr($buff,$i+1,10));
    $buff=trim(fgets($fHandle,1024));
    $fMonth[$myDay]=substr($buff,0,3);
    $myStatus++;
    break;
  case 12: //seeking week
    if (strlen($buff)<3) break;
    $fWeek[$myDay]=substr($buff,0,3);
    $myStatus++;
    break;
  case 13: //seeking min temp
    if (strlen($buff)>4) break;
    $fMin[$myDay]=trim(strip_tags($buff));
    $myStatus++;
    break;
  case 14: //seeking max temp
    if (strlen($buff)>4) break;
    $fMax[$myDay]=trim(strip_tags($buff));
    $myStatus++;
    break;
  case 15: //seeking img
    if (($i=strpos($buff,'<img src=',0))===False) break;
    if (($i=strpos($buff,'"',$i))===False) if (($i=strpos($buff,"'",$i))===False) break;
    if (($j=strpos($buff,'"',$i+1))===False) if (($j=strpos($buff,"'",$i+1))===False) break;
    $fImg[$myDay]=substr($buff,$i+1,$j-$i-1);
    $myStatus++;
    break;
  case 16: //seeking weather
    if (substr($buff,0,7)!='<td><b>') break;
    $buff=trim(fgets($fHandle,1024));
    $fWeather[$myDay]=trim(strip_tags($buff));
    $myStatus=10;
    $myDay++;
  default:
    break;
  }
}
$myXml="<?xml version=\"1.0\" ?>\r\n";
$myXml=$myXml."<forecast>\r\n";
$myXml=$myXml."  <issue>\r\n";
$myXml=$myXml."    <year>$issueYear</year>\r\n";
$myXml=$myXml."    <month>$issueMonth</month>\r\n";
$myXml=$myXml."    <day>$issueDay</day>\r\n";
$myXml=$myXml."  </issue>\r\n";
for ($i=0;$i<$myDay;$i++)
{
  $myXml=$myXml."  <info day=\"$i\">\r\n";
  $myXml=$myXml."    <month>$fMonth[$i]</month>\r\n";
  $myXml=$myXml."    <day>$fDay[$i]</day>\r\n";
  $myXml=$myXml."    <week>$fWeek[$i]</week>\r\n";
  $myXml=$myXml."    <min>$fMin[$i]</min>\r\n";
  $myXml=$myXml."    <max>$fMax[$i]</max>\r\n";
  $myXml=$myXml."    <img>$fImg[$i]</img>\r\n";
  $myXml=$myXml."    <weather>$fWeather[$i]</weather>\r\n";
  $myXml=$myXml."  </info>\r\n";
}
$myXml=$myXml."</forecast>\r\n";
 
return $myXml;
 
}/*--- End function --*/
?>
 
plugins/worldweather/worldweather_code.txt · 最終更新: 2011/03/23 21:28 (外部編集)