nitrus Posted March 19, 2013 Share Posted March 19, 2013 Hello PHP Freaks Forums, I am trying to construct a web app to fetch weather off "http://www.flightstats.com", and look up the airport code and display weather for that airport code in that location. I have some code i started writting that has few errors i need help fixing. The code fetches weather off of the flightstats.com, but i need to figure out how i could make a drop down box or form that a user can type a airport code and fetch the weather from flight stats or if you have better website that works better please feel free to suggest it. Thanks. There is error in line three. <?php $airport_code = $_GET["airport"];; function get_string_between($string, $start, $end) { $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } $data = file_get_contents("http://www.flightstats.com/go/Airport/weather.do?airportCode=".$airport_code.""); $weatherdiv = get_string_between($data, '<table width="237" class="contentTable">', '</table>'); $weathertext = strip_tags($weatherdiv); ?> <table width="237" class="contentTable"> <?php echo $weathertext; ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/275888-fetching-weather-in-php/ Share on other sites More sharing options...
requinix Posted March 19, 2013 Share Posted March 19, 2013 Their Terms of Use prohibits what you're trying to do. With added bolding, Description of Site and License The Site provides information about FlightStats' products and services. The text, images, and other contents of the Site (collectively, the "Contents") are protected by the copyright laws of the United States and other countries. FlightStats grants you a license to view the Contents on the publicly accessible areas of the Site. This license does not include the right to screen scrape, reproduce, distribute, broadcast, modify, or otherwise commercially exploit any of the Contents, except that reproduction incidental to your use of the Site in accordance with these Terms is permitted. The license can be terminated by FlightStats at any time with or without cause. Fortunately they do have a developer center you can visit. Quote Link to comment https://forums.phpfreaks.com/topic/275888-fetching-weather-in-php/#findComment-1419706 Share on other sites More sharing options...
nitrus Posted March 19, 2013 Author Share Posted March 19, 2013 Their Terms of Use prohibits what you're trying to do. With added bolding,Fortunately they do have a developer center you can visit. Is the a another website that i could use for testing purposes? I was also thinking of using Regular expression to fetch data from the html tags would that be better idea? Quote Link to comment https://forums.phpfreaks.com/topic/275888-fetching-weather-in-php/#findComment-1419712 Share on other sites More sharing options...
requinix Posted March 20, 2013 Share Posted March 20, 2013 I can't imagine it being hard to find a database of airports (with codes) and their locations. Pair that up with a generic weather service of which I know there are many. IMO learning how to use a service/API is more useful than how to scrape an HTML page. To answer the question traversing the DOM is a smarter way of doing it than regular expressions, which aren't suited for stuff like HTML in the first place. Unless the HTML is horribly mangled, but it's almost never so bad that it can't be dealt with. Quote Link to comment https://forums.phpfreaks.com/topic/275888-fetching-weather-in-php/#findComment-1419715 Share on other sites More sharing options...
monkeypaw201 Posted March 20, 2013 Share Posted March 20, 2013 @nitrus, I don't intend to advertise or self-promote here, but I have a collection of APIs published with Mashape including a weather API that might help you out. https://www.mashape.com/laiello/weather-4 Hope it helps. If you need some kind of data not readily available there, PM me and I'll see what I can do. Quote Link to comment https://forums.phpfreaks.com/topic/275888-fetching-weather-in-php/#findComment-1419737 Share on other sites More sharing options...
nitrus Posted March 20, 2013 Author Share Posted March 20, 2013 @nitrus, I don't intend to advertise or self-promote here, but I have a collection of APIs published with Mashape including a weather API that might help you out. https://www.mashape.com/laiello/weather-4 Hope it helps. If you need some kind of data not readily available there, PM me and I'll see what I can do. Ok thanks ill see if anything can help me out. I'm looking for api that fetch airport weather tho. I will surely take a look! Quote Link to comment https://forums.phpfreaks.com/topic/275888-fetching-weather-in-php/#findComment-1419864 Share on other sites More sharing options...
monkeypaw201 Posted March 20, 2013 Share Posted March 20, 2013 It does, it's only airport weather Quote Link to comment https://forums.phpfreaks.com/topic/275888-fetching-weather-in-php/#findComment-1419875 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.