code & tutorials / php classes / class weather v2 home contact sitemap search print view add to favourites recommend site guestbook deutsch/german  

« a man travels the world over in search of what he needs and returns home to find it. »
(george moore)

 

 

class yahoo weather v2

i wrote a new php class, that makes it very easy to use weather data from weather.yahoo.com! an integrated caching-system makes it very fast. you can download the class right here for free.

you need only 4 lines of code to get the actual weather situation and 2 day forecast of any location, that is provided by weather.yahoo.com! integrated caching (you can define the cache lifetime by your own) prevents your application to load the same data every page hit. this makes the rss parsing very fast!

this is version 2, provided by matt brown from  http://dowdybrown.com

  1. // Include the classes
  2. include("class.xml.parser.php");
  3. include("class.weather.php");
  4.  
  5.  // LocationCode, seconds cachelifetime, TempUnit (F or C), Cache Directory
  6. $weather_chile = new weather("CIXX0020", 3600, "C", $cachedir);
  7.  
  8. // Parse the weather data with caching
  9. $weather_chile->parsecached()
   

PHPClasses.org view this package on phpclasses.org

weather class fix: xml-feed unreachable

  1.  
  2.  
  3. // Thanks to Daniel Milosevic for the following code snippet!
  4. // It shows how to fix the problem if the XML file cannot be
  5. // reached, due to security settings on the server. It uses
  6. // curl.
  7.  
  8. //If fopen is accessible use below
  9. //if (!($fp = fopen($path, "r"))) {
  10. //die("Cannot open XML data file: $path");
  11. //return false;
  12. //}
  13.  
  14. //If fopen is not accessible because of server settings, use curl below - DM
  15. $file = $path;
  16. $ch = curl_init($file);
  17. $fp = @fopen("temp.xml", "w");
  18. curl_setopt($ch, CURLOPT_FILE, $fp);
  19. curl_setopt($ch, CURLOPT_HEADER, 0);
  20. curl_exec($ch);
  21. curl_close($ch);
  22. fclose($fp);
  23. $file = "temp.xml";
  24. if (!($fp = fopen($file, "r"))){
  25. die("Cannot open XML data file: $file");
  26. return false;
  27. }
  28. // - DM
  29.  
  30.  
 
     
  © by marco voegeli, switzerland       357091 visitors total / © & disclaimer up