Jump to content

POST data dumped to Excel?


komquat

Recommended Posts

You could easily write it to a "csv" file and then open that in Excel.  This code should take all the POST variables and use the keys as the header row and put the values in the row beneath them.  Haven't tested it though.  Also, there is no error checking in this code.

[code]
<?php
foreach ($_POST as $key=>$val) {
  $$key = stripslashes($val);
  $header .= $key.",";
  $data .= $val.",";
}
$header = substr($header,-1)."\n"; //to strip away trailing comma and add a newline character
$data = substr($data,-1);//to strip away trailing comma

$filecontent = $header.$data;  //merge the content

$handle = fopen("yourfilehere.csv","w");
fwrite($handle, $filecontent); // Write $filecontent to your opened file.
fclose($handle);

?>
[/code]
Yeah, you'll have to write it to the server and then download the file.  If you're doing all that, you might as well just echo the data to the screen and then copy-and-paste into Excel on your PC.  Probably faster overall, and definitely less coding.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.