Helpful PHP Output
function output($str,$recursive=null)
{
if (!$recursive)
{
echo '<pre><code>'.$str.'</code></pre>';
}
else
{
echo ('<pre><code>');
print_r($str);
echo ('</code></pre>');
}
}
I put this function in place to make my dev process more efficient. Now, I have less code to write when I just want to see what's going on with a variable. (Inspired by "'Nicer' print_r" by @chdcxa)
Written by vince falconi
Related protips
5 Responses
Great idea. I've always used
echo '<pre>';
print_r($str);
echo '</pre>';
but never though to put it in a function like that.
I've always just used xDebug's ability to overload var_dump
to do exactly the same.
I don't really see any advantage in creating custom methods for things PHP is already quite capable of doing all by itself...
Well, @potherca, I'm not familiar with the xDebug extension. Thanks for that, though.
For what it's worth, on the topic of non-native solutions, I've found using Chrome Logger (http://craig.is/writing/chrome-logger) really helpful, outputting things to the Chrome dev console.
@vfalconi I've used that one too!
Before switching from Firefox to Chrome for web development, I used to use FirePHP.
For a brief period I used Chrome Logger before going with a customized version of chrome-firephp
That way I could view the output both in Chrome and Firefox.
I added a shortcut to ST2 that gives me a pretty printing line, similar to what your function does, that also includes file name, and line number so I can easily find all of them when I am done debugging. See http://coderwall.com/p/3fa_pw