ماژول آب و هوا و کد php آن

mohsen162

Member
با سلام خدمت دوستان راستش من این مبحث جدیدو ساختم که اگه درست بشه همه بتونن راحت پیداش کنند تو سایتشون استفاده کنند
ما یک ماژو آب و هوا به نام ttweather داریم که کاربر نمیتونه شهر مورد نظر رو انتخاب کنهمن دو تا کد جدا به کمک دوستان مخصوص p.h.p درست کردیم به این صورت
کد:
<html>
<body>
<html>

<body>

<form action="mod_ttweather.php" method="post">
<select size="1" name="set" onchange="this.form.submit()"/>
<option value="tehran">tehran</option>
<option value="shiraz">shiraz</option>
<option value="oromie">oromie</option>
<option value="kerman">kerman</option>

</form>

</body>

</html>
</body>
</html>
و
کد:
switch ($_POST["set"] )

{

case "tehran":

  $cities=="2251945";
  $name_sity="تهران";

  break;

case  "shiraz":

  $cities=="2255202";
  $name_sity="شيراز";

  break;

case "oromie":

  $cities=="2242302";
   $name_sity="اروميه";

  break;

default:

  echo "no match";

};

حالا به نظر تون چطوری با این ماژول ترکیب کنیم که جواب بده
کد:
<?php

defined('_JEXEC') or die('Restricted access'); // no direct access
function   day_shams($day_sh)
{

if(trim($day_sh)=="Sat") return "شنبه";
if(trim($day_sh)=="Sun") return "يک شنبه";
if(trim($day_sh)=="Mon") return "دوشنبه";
if(trim($day_sh)=="Tue") return "سه شنبه";
if(trim($day_sh)=="Wed") return "چهار شنبه";
if(trim($day_sh)=="Thu") return "پنج شنبه";
if(trim($day_sh)=="Fri") return "جمعه";


}
?>

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<?php

$cities= $params->def( 'button_pos' );

            if ($cities=="2254796")$name_sity="کرمان"    ;
            if ($cities=="2242302")$name_sity="اروميه"    ;
            if ($cities=="2254463")$name_sity="بوشهر";
            if ($cities=="2254572")$name_sity="اصفهان";
            if ($cities=="2255239")$name_sity="تبريز";
            if ($cities=="2251945")$name_sity="تهران"    ;        
            if ($cities=="2255309")$name_sity="زاهدان";        
            if ($cities=="2255202")$name_sity="شيراز";
            if ($cities=="2254914")$name_sity="مشهد "; 
            if ($cities=="2255297")$name_sity= "یاسوج"; 
            if ($cities=="2254294")$name_sity="اهواز";
           
$file = "http://xml.weather.yahoo.com/forecastrss?p=$cities&u=c";

           
           echo "<tr><td><b><font size=2 face=Tahoma>  $name_sity </font> </b></tr></td>";
$xml_parser = xml_parser_create();
// use case-folding so we are sure to find the name in $map_array


xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
/*xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");*/
if (!($fp = fopen($file, "r"))) {
    die("could not open XML input");
}

while ($data = fread($fp, 4096)) {

xml_parse_into_struct($xml_parser , $data, $vals, $index);

   /* if (!xml_parse($xml_parser, $data, feof($fp)))
   {
        die(sprintf("XML error: %s at line %d",
                    xml_error_string(xml_get_error_code($xml_parser)),
                    xml_get_current_line_number($xml_parser)));
    }*/
}
xml_parser_free($xml_parser);
for  ($i=0;$i<count($vals);$i++)

 { //for
 //echo $vals[$i]['attributes']."</br>";
      //tagname  xml  of  file
       $tag=$vals[$i]['tag'];
            if ($tag=="DESCRIPTION")
                 {
                 $value=$vals[$i]['value'];
                 $poss1=strpos($value,"<img");

                  if ($poss1<0) {$poss1=strpos($value,"<IMG");if ($poss1<0)  continue;}
                 $poss2=strpos($value,">");
                 echo substr($value,$poss1,$poss2)."</BR>";
                 }

        $valss =$vals[$i]['attributes'];


       if (count($valss)>0)
            foreach($valss as  $attribute=>$contain)
                {
        $visit_tag=false;
                  if  (trim($attribute)=="HUMIDITY")  { $attribute='رطوبت';  $contain=$contain."<font color=blue> درصد</font>";  $visit_tag=true;}
                 if  (trim($attribute)=="VISIBILITY")
                   { $attribute='ميدان ديد';if($contain>100) $contain/=100;
                   $contain=$contain."<font color=blue> کيلومتر</font>"; $visit_tag=true;}
                 if  (trim($attribute)=="PRESSURE")  
                  {$attribute='فشار'; if(trim($contain)=="mb")continue;
                  $contain=$contain."<font color=blue> متر مربع</font>";  $visit_tag=true;}
                  if  (trim($attribute)=="TEMP")      { $attribute='دماي فعلي';  $contain=$contain."<font color=blue> درجه  سانتيگراد</font>";  $visit_tag=true;}
                 if   (trim($attribute)=="SUNRISE")   { $attribute='طلوع آفتاب'; $contain=  substr($contain ,0,5).'ق/ظ' ;$visit_tag=true;}
                 if   (trim($attribute)=="SUNSET")    {$attribute='غروب آفتاب'; $contain=  substr($contain ,0,5).'ب/ظ';$visit_tag=true;}
                 if  (trim($attribute)=="DAY")
                  {
                                        $attribute='روز'; ///write  functinon  for recover  dat  to  shamsi
                                        $contain=day_shams($contain);
                                                                $visit_tag=true;
                  }
          if  (trim($attribute)=="LOW") {   $attribute='حداقل';   $contain=$contain."<font color=blue> درجه سانتيگراد</font>";  $visit_tag=true;}
                 if  (trim($attribute)=="HIGH"){    $attribute='حداکثر'; $contain=$contain."<font color=blue> درجه  سانتيگراد</font>"; $visit_tag=true;}
                 if($visit_tag==true)        echo "<tr><td><font size=1  face=Tahoma> $attribute: $contain </font>  </tr></td>";
                }

     //  echo($valss);

//  foreach($valss as  $tag=>$level){      echo "$tag</br>";       }

          }//for
// print_r($vals);
   //   print_r($vals[0]);
//  echo  '<b>dfgfdgfdgd'.$tmp_data[1].$tmp_data[2];
?>

</table>

ممنون میشم روش فکر کنید ماژول زیبایی
 

جدیدترین ارسال ها

بالا