|
Post by [dmsuperman] on Apr 14, 2006 0:54:27 GMT
/* Function.....: nice_print Description..: Same as the print except boolean and null data is converted into a human readable string Syntax.......: nice_echo(<data>);
Example......: nice_print("Test") --> "String -> Test" nice_echo(true) --> "Boolean -> True" nice_echo(null) --> "Null -> Null" nice_echo(0) --> "Integer -> 0"
Input........: Format: mixed
Output.......: Print: string
Author.......: [dmsuperman]
Date(s)......: 3/22/06
Version......: 1.0
*/ function nice_print($input){ print("<pre>"); if($input===false){ print("Boolean -> False"); }else if($input===true){ print("Boolean -> True"); }else if($input===null){ print("Null -> Null"); }else{ if(is_string($input)){ print("String -> " . $input); }else if(is_int($input)){ print("Integer -> " . $input); }else if(is_array($input)){ print_r($input); }else{ print("Unknown -> " . $input); } } print("</pre>"); }
This is like ASP's chr function (I think that's what it's called...) it's basically for debugging, it will take data passed to it and output it in a readable form, so boolean will not just output nothing, it will tell you (Boolean) -> True, integers will have (Integer) before them, null will be displayed as (Null) -> Null, etc.
Do what you want with it...it's not really supposed to be a big thing.
|
|
|
Post by acoolie530 on Apr 14, 2006 13:29:11 GMT
First, of all, I would've used a switch structure on gettype($input).
Anywys, what's the difference between this and var_dump, and var_dump, handles arrays and shows more info =P
Also, the syntax example is wrong, nice_print is the function, not var_echo.
|
|
|
Post by [dmsuperman] on Apr 15, 2006 5:29:18 GMT
I've never heard of var_dump Switch/case is nothing more than a neater way to use an if statement, it wouldn't affect the actual process other than use slightly more resource, so to each his own on that one. As for nice_echo...I renamed it somewhere along the long. Doesn't matter, if this is already included in PHP it can be deleted. Wish I'd have known about var_dump before though lol.
|
|
|
Post by acoolie530 on Apr 15, 2006 13:44:37 GMT
Yeah, var_dump and print_r are really common for debugging purposes. Many comments at php.net include var_dump. Also, switch would just've simplified the code. Adding objects support, etc. would be easier with a switch
|
|