vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   print_r replacement (https://vborg.vbsupport.ru/showthread.php?t=262638)

Boofo 04-25-2011 07:20 PM

print_r replacement
 
I just found this little snippet of code that works great for replacing print_r when working with code, and thought I would share it here. It prints out like this:

Code:

Array
(
    [0] => 5
    [1] => 6
    [2] => 7
)


Here is the code:

PHP Code:

if (!function_exists("preprint")) {
     function 
preprint($s$return=false) {
         
$x "<pre>";
         
$x .= print_r($s1);
         
$x .= "</pre>";
         if (
$return) return $x;
         else print 
$x;
     }
 } 


@usage:

PHP Code:

preprint($x);   <- where $x = array() 


NOTE: The optional 2nd parameter can be set to "true", so the html-code is returned.

I haven't quite figured out what the 2nd perimeter actually does as no code has shown up for me when that has been enabled.

Disasterpiece 04-26-2011 07:24 AM

var_dump() / var_export() ?

Why re-invent the wheel?

Boofo 04-26-2011 07:25 PM

That does not format it so it is easily readable.

If you don't like it, don't use it. Keep the sarcastic comments to yourself.

Disasterpiece 04-26-2011 07:31 PM

Dude, what is wrong with you!?

Just trying to help, sorry :/

Boofo 04-26-2011 07:53 PM

I just woke up and that post was the first thing I saw. Maybe I read it wrong, If so, I apologize.

But, var_dump or var_export shows it all in one line. The pre tags format it so it is easier to view. I had been using var_dump until I found this.


All times are GMT. The time now is 08:59 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02167 seconds
  • Memory Usage 1,718KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete