bobohob Posted August 31, 2007 Share Posted August 31, 2007 How to display the result of print_r vertically ? It display like this (horizontal) : Array ([0] => fruit [1] => animal [2] => machine ) I was hoping it would display vertically : (see the image below) or http://au.php.net/print_r Thanks. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/67403-print_r-how-to-display-it-vertically/ Share on other sites More sharing options...
btherl Posted August 31, 2007 Share Posted August 31, 2007 Try this: print "<pre>"; print_r($var); print "</pre>"; The other option is: print nl2br(print_r($var, true)); Quote Link to comment https://forums.phpfreaks.com/topic/67403-print_r-how-to-display-it-vertically/#findComment-338390 Share on other sites More sharing options...
bobohob Posted August 31, 2007 Author Share Posted August 31, 2007 Thanks. It works! but it doesn't have indentation. btw why this never been mentioned in the tutorial/doc like http://au.php.net/print_r (they just give print_r while the result on their page is vertical) ? Quote Link to comment https://forums.phpfreaks.com/topic/67403-print_r-how-to-display-it-vertically/#findComment-338401 Share on other sites More sharing options...
hvle Posted August 31, 2007 Share Posted August 31, 2007 try this, echo str_ireplace(array("\n"," "),array('<br>',' '),print_r($arr,true)); it should preserve tab as well Quote Link to comment https://forums.phpfreaks.com/topic/67403-print_r-how-to-display-it-vertically/#findComment-338405 Share on other sites More sharing options...
btherl Posted September 2, 2007 Share Posted September 2, 2007 The result IS vertical, when displayed as text. It's just not vertical when displayed as HTML. If you view the source of the page, you'll see the formatting which you see in the documentation. Quote Link to comment https://forums.phpfreaks.com/topic/67403-print_r-how-to-display-it-vertically/#findComment-339733 Share on other sites More sharing options...
Barand Posted September 2, 2007 Share Posted September 2, 2007 the nl2br version won't indent but pre tags will <?php $ar = array ( 'abc' => array (1,2,3), 'def' => array (7,8,9) ); echo '<pre>', print_r($ar, true), '</pre>'; ?> Array ( [abc] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [def] => Array ( [0] => 7 [1] => 8 [2] => 9 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/67403-print_r-how-to-display-it-vertically/#findComment-339760 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.