3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<html> <body onload="showProduct()"> <div id="dropdown"> <?php /** * Download & parse Google spreadsheet content * * @param unknown_type $link */ function google_spreadsheet_to_array($key) { // initialize URL $url = 'http://spreadsheets.google.com/feeds/cells/' . $key . '/1/public/values'; // initialize curl $curl = curl_init(); // set curl options curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // get the spreadsheet using curl $google_sheet = curl_exec($curl); // close the curl connection curl_close($curl); // import the xml file into a SimpleXML object $feed = new SimpleXMLElement($google_sheet); // get every entry (cell) from the xml object // extract the column and row from the cell's title // e.g. A1 becomes [1][A] $array = array(); foreach ($feed->entry as $entry) { $location = (string) $entry->title; preg_match('/(?P<column>[A-Z]+)(?P<row>[0-9]+)/', $location, $matches); $array[$matches['row']][$matches['column']] = (string) $entry->content; } // return the array return $array; } $SP_KEY = "0AjzADOdg6QnadHZTVDI5MU83NVE4MFpxMmFHOXR2S1E"; $data = google_spreadsheet_to_array($SP_KEY); echo' <select name="Product" id="Product" onchange="showProduct()">'; foreach($data[1] as $products){ echo'<option value="'.$products.'">'.$products.'</option>'; } echo'</select>\n\n'; echo' <select name="Category" id="Category" onchange="showProduct()">'; foreach($data as $categories){ if($categories[A] != "Product" and $categories[A] != "") echo'<option value="'.$categories[A].'">'.$categories[A].'</option>'; } ?> <div id="demo"> </div> <script> function showProduct() { var product = document.getElementById('Product').value; document.getElementById("demo").innerHTML="bloop "+product+"!"; } </script> </div> </body> </html>
Output for 7.0.0 - 7.1.0
<html> <body onload="showProduct()"> <div id="dropdown"> Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/O0A65:16 Stack trace: #0 /in/O0A65(48): google_spreadsheet_to_array('0AjzADOdg6QnadH...') #1 {main} thrown in /in/O0A65 on line 16
Process exited with code 255.
Output for 5.0.0 - 5.6.23
<html> <body onload="showProduct()"> <div id="dropdown"> Fatal error: Call to undefined function curl_init() in /in/O0A65 on line 16
Process exited with code 255.
Output for 4.4.5 - 4.4.9
<html> <body onload="showProduct()"> <div id="dropdown"> Fatal error: Call to undefined function: curl_init() in /in/O0A65 on line 16
Process exited with code 255.
Output for 4.3.2 - 4.4.4
<html> <body onload="showProduct()"> <div id="dropdown"> Fatal error: Call to undefined function: curl_init() in /in/O0A65 on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1
<html> <body onload="showProduct()"> <div id="dropdown"> Fatal error: Call to undefined function: curl_init() in /in/O0A65 on line 16