Forked from uppfinnarjohnny/get_google_spreadsheet.php
Created
November 6, 2013 07:32
-
-
Save reinislejnieks/7332310 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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