Jump to content


Photo

Output object/array information to a variable?


  • Please log in to reply
2 replies to this topic

#1 drewjoh

drewjoh
  • Members
  • PipPip
  • Member
  • 24 posts
  • LocationTexas

Posted 03 April 2006 - 06:55 PM

I'm trying to get the same effect you get say you have an array, and you can output the contents to the screen in a nice formatted way.

ie: print_r($array);

gives you:
array => Array
   element1 => value1
   element2 => value2

What I need though, is to have this formatted output given to a variable... what I'm trying to do is mail the results to myself.

Doing something like mail($to, $subject, print_r($array)); doesn't work, it just gives me a number.

Any ideas? :)

#2 kenrbnsn

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

Posted 03 April 2006 - 07:11 PM

If you look at the [a href=\"http://www.php.net/print_r\" target=\"_blank\"]manual page[/a] for the print_r() function, you will see that it takes a second parameter. When that parameter, the output can be assigned to a variable.

Example:
<?php
echo '<pre>' . print_r($_SERVER,true) . '</pre>';
//
//   or
//
$body = print_r($_SERVER,true);
?>

Ken

#3 drewjoh

drewjoh
  • Members
  • PipPip
  • Member
  • 24 posts
  • LocationTexas

Posted 03 April 2006 - 07:32 PM

OHHH, awesome. Thanks Ken.

I had read that but didn't comprehend what exactly the bool return meant.

Thank you, thank you :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users