Jump to content


Photo

Store contents of an array export into a new variable


  • Please log in to reply
4 replies to this topic

#1 purefusion

purefusion
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 06 April 2006 - 06:06 PM

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!



#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 06 April 2006 - 06:16 PM

<?php

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

?>
The output of var_dump($_POST) is now in $var.

#3 purefusion

purefusion
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 06 April 2006 - 06:24 PM

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.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 April 2006 - 06:26 PM

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
<?php $body = print_r($_POST,true); ?>
If you just want to display it on the screen, do
<?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?>

Ken

#5 purefusion

purefusion
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 06 April 2006 - 06:34 PM

kenrbnsn, awesome! Thank you!

Works perfectly :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users