Nog korter, zonder loop:
<?php
eval(str_replace(array("BOF", "EOF", "\n"), "", file_get_contents ("http://weerstation-brugge.be/customtextout10.txt").';'));
echo $sunriseTime;
?>
J
John Berg
25-08-2012 20:01
gewijzigd op 25-08-2012 20:12
Als kers op de taart, de implementatie zoals ik hem zou maken (zonder foutafhandeling)
<?php
// in het bestand weerstation.php
class Weerstation
{
const Brugge = "http://weerstation-brugge.be/customtextout10.txt";
const Waregem = "http://weerwaregem.be/data/customtextout10.txt"
function LeesBericht( $station )
{
$a = explode("\n", file_get_contents ( $station ));
foreach ( $a as $value )
if ( strpos( $value, '$' ) !== false )
eval( str_replace ( '$', '$this->', $value) );
}
}
// het gebruik
include weerstation.php
$weerstation = new Weerstation();
$weerstation->LeesBericht( Weerstation::Brugge );
echo $weerstation->sunriseTime;
$weerstation->LeesBericht( Weerstation::Waregem );
echo '<pre>';print_r( $weerstation ); echo '</pre>';
?>
ik zag in een ander topic dat er ook een station in Waregem was, dat heb ik er nu bijgezet.