MainelyDesign.com Blog

Displaying phpinfo() without CSS styles

Posted on 06/09/2009 at 10:18 am by Kevin Wentworth
Viewed 22,732 times | 1 comment

I wanted logged in users to be able to see the output from phpinfo(); within Site Avenger.  The problem with using phpinfo() is that it outputs a full HTML page, CSS styles and all.  In the past this has been fine, but now I wanted to show the phpinfo() within the Site Avenger layout and CSS styles.  I came across a simple, yet highly effective solution...

Using Output Buffering to Capture PHPINFO()

The solution is as simple as turning on output buffering, capturing the echo'ed value of phpinfo(); and then using preg_replace to only return what's in between the <body></body> tags.  Here's the code:

  1. $pinfo = ob_get_contents();
  2.  
  3. $pinfo = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1',$pinfo);
  4. echo $pinfo;

Styling PHPINFO() with CSS

I didn't want to use any styles (they were already defined for Site Avenger), so this is just a reference.  You can style the phpinfo() table using the following CSS selectors:

  1. <style type="text/css">
  2. #phpinfo {}
  3. #phpinfo pre {}
  4. #phpinfo a:link {}
  5. #phpinfo a:hover {}
  6. #phpinfo table {}
  7. #phpinfo .center {}
  8. #phpinfo .center table {}
  9. #phpinfo .center th {}
  10. #phpinfo td, th {}
  11. #phpinfo h1 {}
  12. #phpinfo h2 {}
  13. #phpinfo .p {}
  14. #phpinfo .e {}
  15. #phpinfo .h {}
  16. #phpinfo .v {}
  17. #phpinfo .vr {}
  18. #phpinfo img {}
  19. #phpinfo hr {}
  20. </style>

Thanks, to this post at php.net for leading me to such an elegant solution.

Cheers,

-Kevin Wentworth

 

Bookmark and Share

Tags for Displaying phpinfo() without CSS styles

Cakephp | Web Programming | Site Avenger | Php | Css

Comments for this Posting

Posted by MadtownLems

on 26/5/10

Worked great for my WordPress plugin! thanks!

Sorry, comments are closed for this posting.

Please Email Kevin if you have any questions. Thanks!

Meet Site Avenger - Hosted Content Management System

Powered By: Site Avenger | Site Production: Saco Design