Re: Gimpster.com: Home > PHP > PHP Weather > Support
Brought to you by:
iridium
From: Carsten K. <car...@ma...> - 2002-02-20 06:56:19
|
Hi, PhpWeather is really cool! I started writing a PhpWeather plugin for PhpWiki, so it can call PHPWeather. I have a suggestion which might make PhpWeather easier to include in other web sites. In order to arbitrarily embed the output from PhpWeather at a specific location on the page, it would be helpful if the entire weather code could be wrapped up in a single function, so the user would only have to worry about 1 include. The function would also return the result as a string rather than using print to try to do the output itself. Such a function could be called something like this: <?php // my great php application $icao = "CYYZ"; $language = 'en'; $format = 'metar'; $name = "Toronto Pearson Int\'l Airport / Ontario, Canada"; require_once('phpweather.inc'); $weather = PHPWeather($icao, $format, $language, $name); // somewhere, deep in the web site... printf("<table summary="Local weather via PHPWeather"><tr><td>%s</td></tr> </table>", $weather); ?> // inside 'phpweather.inc'... <?php // PHPWeather wrapper function /** * This is a convenience wrapper function for PHPWeather */ function PHPWeather($icao, $format = 'pretty', $language = 'en', $name = ' ') { include(sprintf('locale_%s.inc', $language)); switch ($format) { case 'pretty': return pretty_print_metar($icao, $format, $language, $name); break; case 'metar': return get_metar($icao); break; } //...etc } ?> The whole phpweather.inc probably could be rewritten using classes too, but I haven't had time to delve inside the code yet, PhpWiki keeps me busy. Carsten CC: replies to <car...@ma...> (I'm not on the mailing-list). |