Using Google Docs as a quick and easy CMS

In search for a simple CMS to use on a holding page, my thoughts turned to Google Doc’s. 10 minutes later I had a script that works very nicely, so thought I would share it. To use:

  • Create a Google Document
  • Click ‘Share’
  • Click ‘Publish as a website…’
  • Copy and paste the document reference into the script e.g. http://docs.google.com/View?id=dd9zpc9r_4jh8qv76j

<?php
// Use the script freely , but if it's useful then please post a comment - thanks James
// Ps. the array is used to later experiment with spreadsheets etc...
 
// Specify document
$gd_doc = "dd9zpc9r_4jh8qv76j";
$gd_doc_type = "doc";
 
$gd_array = array();
 
$gd_array["doc"]["url"] = "http://docs.google.com/View?id=".$gd_doc;	
$gd_array["doc"]["start"] = '<div id="doc-contents">';
$gd_array["doc"]["end"] = '<div id="google-view-footer">';	
 
$working_doc = file_get_contents($gd_array[$gd_doc_type]["url"]);
$gd_start = strpos($working_doc,$gd_array[$gd_doc_type]["start"]);
$gd_end = strpos($working_doc,$gd_array[$gd_doc_type]["end"]);	
$gd_content = substr($working_doc, $gd_start, ($gd_end-$gd_start) )
?>
 
<?=$gd_content?>