Skip to content

Instantly share code, notes, and snippets.

@uppfinnarjohnny
Created March 16, 2011 11:11
Show Gist options
  • Save uppfinnarjohnny/872333 to your computer and use it in GitHub Desktop.
Save uppfinnarjohnny/872333 to your computer and use it in GitHub Desktop.
A simple way of getting the data from a Google Docs Spreadsheet in PHP
<?php
function get_google_spreadsheet($key) {
$url = "https://spreadsheets.google.com/feeds/list/{$key}/od6/public/values";
$google_sheet = file_get_contents($url);
$xml = simplexml_load_string($google_sheet);
$data = array();
foreach($xml->entry as $entry) {
$row = array();
// The fields are in the gsx: namespace, so we need to specify that to be able to access them through SimpleXML.
$fields = $entry->children('http://schemas.google.com/spreadsheets/2006/extended');
foreach($fields as $id => $field)
$row[$id] = (string) $field;
$data[] = $row;
}
return $data;
}
$key = "your-document-key";
$data = get_google_spreadsheet($key);
print_r($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment