purefusion Posted April 6, 2006 Share Posted April 6, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/6748-store-contents-of-an-array-export-into-a-new-variable/ Share on other sites More sharing options...
trq Posted April 6, 2006 Share Posted April 6, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/6748-store-contents-of-an-array-export-into-a-new-variable/#findComment-24541 Share on other sites More sharing options...
purefusion Posted April 6, 2006 Author Share Posted April 6, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6748-store-contents-of-an-array-export-into-a-new-variable/#findComment-24544 Share on other sites More sharing options...
kenrbnsn Posted April 6, 2006 Share Posted April 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/6748-store-contents-of-an-array-export-into-a-new-variable/#findComment-24546 Share on other sites More sharing options...
purefusion Posted April 6, 2006 Author Share Posted April 6, 2006 kenrbnsn, awesome! Thank you!Works perfectly :) Quote Link to comment https://forums.phpfreaks.com/topic/6748-store-contents-of-an-array-export-into-a-new-variable/#findComment-24550 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.