Skip to content

Instantly share code, notes, and snippets.

@mhawksey
Created January 31, 2011 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhawksey/804918 to your computer and use it in GitHub Desktop.
Save mhawksey/804918 to your computer and use it in GitHub Desktop.
<?php
function getCSVfromGoogle($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.rsc-ne-scotland.org.uk/mashe");
$arr = importCSV(curl_exec($ch), true);
curl_close($ch);
return $arr;
}
function importCSV($input,$head=false,$delim=",",$len=5000) {
$return = array();
$fiveMBs = 5 * 1024 * 1024;
$handle = fopen("php://temp/maxmemory:$fiveMBs", 'r+');
fputs($handle, $input);
rewind($handle);
if ($head) {
$header = fgetcsv($handle, $len, $delim);
}
while (($data = fgetcsv($handle, $len, $delim)) !== FALSE) {
$return[$data[0]] = $data[1];
}
fclose($handle);
return $return;
}
$data = getCSVfromGoogle("https://spreadsheets.google.com/pub?key=0AqGkLMU9sHmLdDdYRU11dnFib1lYTG5LTHVjLUJ6TEE&single=true&gid=3&output=csv");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment