Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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