Forked from uppfinnarjohnny/get_google_spreadsheet.php
Created
November 18, 2015 06:46
-
-
Save udithishara/9829b3f90e766bae46f0 to your computer and use it in GitHub Desktop.
A simple way of getting the data from a Google Docs Spreadsheet in PHP
This file contains 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