PHP Helpers: html_print_r

Before I get to the next PHP Helpers function I wanted to mention that I’ve made the code available as a Google Code Project at http://code.google.com/p/php-helpers/. I added specific licensing terms ( MIT style ) – http://code.google.com/p/php-helpers/source/browse/trunk/license.txt. There’s also a changelog available to see when functions were added.

With that out of the way here’s the next PHP Helpers function, html_print_r:

if ( !function_exists( 'html_print_r' ) ) {
    function html_print_r( $data ) {
        $out = "\n<pre class='html-print-r'";
        $out .= " style='border: 1px solid #ccc; padding: 7px;'>\n";
        $out .= esc_html( print_r( $data, TRUE ) );
        $out .= "\n</pre>\n";

        return $out;
    }
}

I added this because I use PHP’s print_r in an HTML context quite a bit. To make the output look reasonable I was always adding PRE tags, which got boring fast.

Related posts:

  1. PHP Helpers: html_var_dump
  2. PHP Helpers: esc_html
  3. PHP Helpers: debug_log
  4. PHP Helpers: redirect_url
  5. PHP Helpers: make_slug

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Comments »

 
 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>