SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Mar 2004
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    weather script - displaying dregrees Celsius instead of Fahrenheit

    Hi, I run this script to retrieve weather info from msnbc.com on my hopmepage. However this does only display Farenheit, but I need it in Celsuis. I'm not that great with PHP, so maybe ther is someone who can help me. How can I acheive this?

    Code:
    <?php
    
    if (!$accid) {
    	$accid="UKXX1764"; # Your default city location code, please change to your city ACCID code.
    }
    
    
    
    $url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";
    
    $fa = fopen($url,"r");
    
    /*
    $fa = fsockopen("www.msnbc.com", 80, &$num_error, &$str_error, 30);
    if(!$fa)
       { print "Weather is not available: $str_error ($num_error)\n"; }
    else
    {
      fputs($fa,"GET /m/chnk/d/weather_d_src.asp?acid=WRRR HTTP/1.0\n\n"); # Replace WRRR with your city ACID code!
      $answer=fgets($fa,128);
    */
    
      $v_City    = "";
      $v_SubDiv  = "";
      $v_Country = "";
      $v_Region  = "";
      $v_Temp    = "";
      $v_CIcon   = "";
      $v_Clouds  = "";
      $v_WindS   = "";
      $v_WindD   = "";
      $v_Baro    = "";
      $v_Humid   = "";
      $v_Real    = "";
      $v_UV      = "";
      $v_Vis     = "";
      $v_LastUp  = "";
      $v_Fore    = "";
      $v_Acid    = "";
    
    $v_Text[] = "N/A!";
    $v_Text[1] = "Rain/Wind";
    $v_Text[3] = "Rain/T-Storms";
    $v_Text[4] = "T-Storms";
    $v_Text[5] = "Cloudy";
    $v_Text[6] = "";
    $v_Text[7] = "Snow/Icy";
    $v_Text[8] = "";
    $v_Text[9] = "";
    $v_Text[10] = "";
    $v_Text[11] = "Light Rain";
    $v_Text[12] = "Rain";
    $v_Text[13] = "Scattered Flurreis";
    $v_Text[14] = "Light Snow";
    $v_Text[15] = "";
    $v_Text[16] = "";
    $v_Text[17] = "";
    $v_Text[18] = "";
    $v_Text[19] = "Dusty";
    $v_Text[20] = "Foggy";
    $v_Text[21] = "Haze";
    $v_Text[22] = "Smoke";
    $v_Text[23] = "Wind";
    $v_Text[24] = "Cloudy/Wind";
    $v_Text[25] = "Extremely Cold";
    $v_Text[26] = "Cloudy";
    $v_Text[27] = "Mostly Cloudy";
    $v_Text[28] = "Mostly Cloudy";
    $v_Text[29] = "Partly Cloudy";
    $v_Text[30] = "Partly Cloudy";
    $v_Text[31] = "Partly Cloudy";
    $v_Text[32] = "Sunny";
    $v_Text[33] = "";
    $v_Text[34] = "Mostly Sunny";
    $v_Text[35] = "";
    $v_Text[36] = "Extremely Hot";
    $v_Text[37] = "Isolated T-Storms";
    $v_Text[38] = "Sct T-Storms";
    $v_Text[39] = "Showers";
    $v_Text[40] = "Showers";
    $v_Text[41] = "Snow";
    $v_Text[41] = "Light Wind";
    $v_Text[43] = "Snow/Wind";
    $v_Text[44] = "Partly Coudy";
    
    
      while (!feof($fa))
         {
         $grabline = fgets($fa, 4096);
         $grabline= trim($grabline) . "\n";
         if (substr($grabline,7,4) == "City")    { $v_City    = substr($grabline,15,20); }
         if (substr($grabline,7,6) == "SubDiv")  { $v_SubDiv  = substr($grabline,17,20); }
         if (substr($grabline,7,7) == "Country") { $v_Country = substr($grabline,18,20); }
         if (substr($grabline,7,6) == "Region")  { $v_Region  = substr($grabline,17,20); }
         if (substr($grabline,7,5) == "Temp ")    { $v_Temp   = substr($grabline,15,20); }
         if (substr($grabline,7,5) == "CIcon")   { $v_CIcon   = substr($grabline,16,20); }
         if (substr($grabline,7,3) == "Clouds")  { $v_Clouds  = substr($grabline,14,20); }
         if (substr($grabline,7,5) == "WindS")   { $v_WindS   = substr($grabline,16,20); }
         if (substr($grabline,7,5) == "WindD")   { $v_WindD   = substr($grabline,16,20); }
         if (substr($grabline,7,4) == "Baro")    { $v_Baro    = substr($grabline,15,20); }
         if (substr($grabline,7,5) == "Humid")   { $v_Humid   = substr($grabline,16,20); }
         if (substr($grabline,7,4) == "Real")    { $v_Real    = substr($grabline,15,20); }
         if (substr($grabline,7,2) == "UV")      { $v_UV      = substr($grabline,13,20); }
         if (substr($grabline,7,3) == "Vis")     { $v_Vis     = substr($grabline,14,20); }
         if (substr($grabline,7,6) == "LastUp")  { $v_LastUp  = substr($grabline,17,20); }
         if (substr($grabline,7,4) == "Fore")    { $v_Fore    = substr($grabline,15,200); }
         if (substr($grabline,7,4) == "Acid")    { $v_Acid    = substr($grabline,15,20); }
    //     print $grabline . "\n";
         }
    
      $v_City    = substr($v_City,0,strlen($v_City)-3);
      $v_SubDiv  = substr($v_SubDiv,0,strlen($v_SubDiv)-3);
      $v_Country = substr($v_Country,0,strlen($v_Country)-3);
      $v_Region  = substr($v_Region,0,strlen($v_Region)-3);
      $v_Temp    = substr($v_Temp,0,strlen($v_Temp)-3);
      $v_CIcon   = substr($v_CIcon,0,strlen($v_CIcon)-3);
      $v_Clouds  = substr($v_Clouds,0,strlen($v_Clouds)-3);
      $v_WindS   = substr($v_WindS,0,strlen($v_WindS)-3);
      $v_WindD   = substr($v_WindD,0,strlen($v_WindD)-3);
      $v_Baro    = substr($v_Baro,0,strlen($v_Baro)-3);
      $v_Humid   = substr($v_Humid,0,strlen($v_Humid)-3);
      $v_Real    = substr($v_Real,0,strlen($v_Real)-3);
      $v_UV      = substr($v_UV,0,strlen($v_UV)-3);
      $v_Vis     = substr($v_Vis,0,strlen($v_Vis)-3);
      $v_LastUp  = substr($v_LastUp,0,strlen($v_LastUp)-3);
      $v_Fore    = substr($v_Fore,0,strlen($v_Fore)-3);
      $v_Acid    = substr($v_Acid,0,strlen($v_Acid)-3);
    
      print "<table border=\"0\" width=\"104\" cellspacing=\"1\" cellpadding=\"0\"><tr><td width=\"50%\" align=\"center\" valign=\"top\">";
      print "<img src=\"/i/". $v_CIcon . ".gif\"></td>";
      print "<td width=\"50%\" align=\"center\" valign=\"middle\"><span class=\"weathertemp\">"     . $v_Temp     . "&deg;F<br>\n";
      print "</span></td></tr><tr><td align=\"center\" colspan=\"2\"><span class=\"v10\"> ".$v_Text[$v_CIcon]."\n";
      print "</span></td></tr></table>\n";
    
      fclose($fa);
    //}
    
    ?>

  2. #2
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Pittsburgh PA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    before your print code, right before:
    PHP Code:
    $temp = ($v_Temp-32)*(5/9); 
    Then in the third print line, change $v_Temp to $temp
    That should make you good to go.
    Juggalo Forums ~ A true juggalo community come to life.
    TekBuzz ~ Under Construction
    Crystal Ball Developing ~ Under Construction

  3. #3
    SitePoint Addict
    Join Date
    Mar 2004
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot Mr. Happy. It works!
    Small Problem though: It displays a lot of digests after the dot, for example:
    2.7777777777778C

    That's a bit mad. Ideally this should say 3C. How can this be acheived?

    Thanks!!

  4. #4
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Pittsburgh PA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     $temp = ($v_Temp-32)*(5/9); 
     
    $temp round($temp);
    // $temp = round($temp,1) this would display 2.8 as opposed to 3 
    Try that.
    Juggalo Forums ~ A true juggalo community come to life.
    TekBuzz ~ Under Construction
    Crystal Ball Developing ~ Under Construction

  5. #5
    SitePoint Addict
    Join Date
    Mar 2004
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Mr Happy, you've made me very happy!!
    All working great now. Thanks!

  6. #6
    SitePoint Member
    Join Date
    Mar 2005
    Location
    Pittsburgh PA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem glad I could help ^_^
    Juggalo Forums ~ A true juggalo community come to life.
    TekBuzz ~ Under Construction
    Crystal Ball Developing ~ Under Construction


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •