Jump to content

Archived

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

purefusion

Store contents of an array export into a new variable

Recommended Posts

Hi. I'm looking to store the string printed by either var_dump(), var_export() or printr() into a new non-array variable for quick sending of email. Any ideas?

Also, is there such a thing as a "Pretty" Variable Dump? Maybe a loop that would store the array in a pretty string format?

It's not important enough that it needs to be formatted to look nice, but there is a lot of information coming from the form.

Thanks so much!

Share this post


Link to post
Share on other sites
[code]
<?php

  ob_start();
  var_dump($_POST);
  $var = ob_get_contents();
  ob_end_clean();

?>
[/code]
The output of var_dump($_POST) is now in $var.

Share this post


Link to post
Share on other sites
Thorpe, thank you. Now what happens if I'm already using ob on the page. Is there another way to loop the array contents into a string as Key -> Value without using objects?

Thanks again.

Share this post


Link to post
Share on other sites
The [a href=\"http://www.php.net/var_export\" target=\"_blank\"]var_export()[/a] and [a href=\"http://www.php.net/print_r\" target=\"_blank\"]print_r()[/a] function will both send their output to a variable if the second parameter is "true".

So to send in email, you can do
[code]<?php $body = print_r($_POST,true); ?>[/code]
If you just want to display it on the screen, do [code]<?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

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.