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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.