Skip to content

Instantly share code, notes, and snippets.

@mgng
Created March 25, 2011 08:03
Show Gist options
  • Save mgng/886520 to your computer and use it in GitHub Desktop.
Save mgng/886520 to your computer and use it in GitHub Desktop.
<?php
$url = 'http://www.tepco.co.jp/forecast/html/images/juyo-j.csv';
$csv = @file($url, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ( !$csv ) {
exit('error');
}
$data = array();
for($i=5,$len=count($csv); $i<$len; $i++) {
$tmp = explode(',', $csv[$i]);
$data[] = array(
'date' => str_replace('/', '-', $tmp[0]) . ' ' . $tmp[1],
'today' => $tmp[2],
'yestaday' => $tmp[3],
'used' => ((int)$tmp[3] !== 0) ? floor((int)$tmp[2] / (int)$tmp[3] * 100) : 0,
);
}
print_r($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment