Edmonds Commerce Logo
  • home
    • blog
  • ecommerce
    • product catalogue
    • order processing
    • customer services
    • stock control
    • human resources
    • management information
  • development
    • oscommerce
    • php
    • mysql
    • open source
    • performance tuning
  • design
  • marketing
  • contact us
    • pricing

Edmonds Commerce Blog

Freelance PHP Ecommerce and SEO Developer in the UK

Latest Posts

Securing a LAMP Server with mod_security
osCommerce Easypopulate File Creator Class
CRELoaded Remove Google Ads -
ICECat Integration with osCommerce, Magento etc

Most Popular Posts

PHP Email Attachment Function Freelance osCommerce UK Ultimate osCommerce Checkout - Fast and Friendly PHP : Dead Easy Excel Export

Advanced PHP Debug Function

March 20th, 2008
Read More php

I have taken the debug function about as far as I can think of. This function will now take a variable and display it all in a nice easy to read format. It will also give the name of the variable being examined. It works with html, using htmlentites. It preserves the tab layout formatting for arrays making it easy to understand:

Heres How to Use It:

PLAIN TEXT
PHP:
  1. //For example, displaying $_POST information
  2. dbug($_POST);
  3.  
  4. //If using inside a function
  5. function something($blah){
  6. dbug($blah, get_defined_vars());
  7. }

Note that if called within the scope of a function (for example) you must give get_defined_vars().

And here are the neccessary functions

PLAIN TEXT
PHP:
  1. //DEbug Functions
  2.  
  3. //convert tabs to spaces
  4. function tab2space($text){
  5.     $text = str_replace('  ', '  ', $text);
  6.     $text = str_replace("\t", '    ', $text);
  7.     return $text;
  8. }
  9.  
  10. //return name of variable passed by reference
  11. function vname(&$var, $scope=false){
  12.     if($scope) $vals = $scope;
  13.     else      $vals = $GLOBALS;
  14.     $old = $var;
  15.     $new = 'THISONE';
  16.     $var = $new;
  17.     $vname = false;
  18.     foreach($vals as $key => $val) {
  19.         if($val !=='var'){
  20.             if($val === $new) $vname = $key;
  21.         }
  22.     }
  23.     $var = $old;
  24.     return $vname;
  25.   }
  26.  
  27.  
  28. function dbug(&$item, $scope=false){
  29.     $vname = vname(&$item,$scope);
  30.     echo '<hr><h3>Debug Info: $' . $vname  . '</h3>' . tab2space(nl2br(htmlentities(var_export($item, true)))) . '<hr>';   
  31. }

Bookmark this Post
Add 'Advanced PHP Debug Function' to Del.icio.usAdd 'Advanced PHP Debug Function' to diggAdd 'Advanced PHP Debug Function' to FURLAdd 'Advanced PHP Debug Function' to blinklistAdd 'Advanced PHP Debug Function' to redditAdd 'Advanced PHP Debug Function' to Feed Me LinksAdd 'Advanced PHP Debug Function' to TechnoratiAdd 'Advanced PHP Debug Function' to Yahoo My WebAdd 'Advanced PHP Debug Function' to NewsvineAdd 'Advanced PHP Debug Function' to SocializerAdd 'Advanced PHP Debug Function' to Ma.gnoliaAdd 'Advanced PHP Debug Function' to Stumble UponAdd 'Advanced PHP Debug Function' to Google BookmarksAdd 'Advanced PHP Debug Function' to RawSugarAdd 'Advanced PHP Debug Function' to SquidooAdd 'Advanced PHP Debug Function' to SpurlAdd 'Advanced PHP Debug Function' to BlinkBitsAdd 'Advanced PHP Debug Function' to NetvouzAdd 'Advanced PHP Debug Function' to RojoAdd 'Advanced PHP Debug Function' to BlogmarksAdd 'Advanced PHP Debug Function' to ShadowsAdd 'Advanced PHP Debug Function' to Co.mments
Add 'Advanced PHP Debug Function' to ScuttleAdd 'Advanced PHP Debug Function' to BloglinesAdd 'Advanced PHP Debug Function' to TailrankAdd 'Advanced PHP Debug Function' to SegnaloAdd 'Advanced PHP Debug Function' to OKnotizieAdd 'Advanced PHP Debug Function' to NetscapeAdd 'Advanced PHP Debug Function' to Bookmark.itAdd 'Advanced PHP Debug Function' to AskAdd 'Advanced PHP Debug Function' to SmarkingAdd 'Advanced PHP Debug Function' to LinkagogoAdd 'Advanced PHP Debug Function' to DeliriousAdd 'Advanced PHP Debug Function' to SocialdustAdd 'Advanced PHP Debug Function' to Live-MSNAdd 'Advanced PHP Debug Function' to SlashDotAdd 'Advanced PHP Debug Function' to SphinnAdd 'Advanced PHP Debug Function' to DiggitaAdd 'Advanced PHP Debug Function' to SeotribuAdd 'Advanced PHP Debug Function' to FaceBookAdd 'Advanced PHP Debug Function' to UpnewsAdd 'Advanced PHP Debug Function' to WikioAdd 'Advanced PHP Debug Function' to Social Bookmarking Reloaded

Feed | Respond | Trackback

Leave a Reply

  • RSS Feed
  • Categories

    • apache
    • barcode
    • creloaded
    • curl
    • customer services
    • debugging
    • ecommerce
    • email
    • excel
    • firefox
    • flash
    • gd
    • graphs
    • hosting
    • icecat
    • internet news
    • javascript
    • link building
    • linux
    • magento
    • management
    • mod_rewrite
    • mysql
    • oscommerce
    • php
    • plesk
    • product catalogue
    • product feed
    • programming
    • regular expressions
    • scraping
    • search engine optimisation
    • security
    • spidering
    • ubuntu
    • web design
    • web development
    • Windows
    • xampp
    • zip
  • Archives

    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
  • Tags

    addons advanced adverts blackhat blocking css curl development directories find firefox google hosts file html javascript keywords links msn mysql myths operators oscommerce paid links paid placement performance php ppc reciprocal linking replace screen scraping security seo serp speed spider spidering tuning user friendly vista web web design web developer
  • Random Posts

    • Using cURL with XAMPP
    • PHP Generated SQL
    • Plesk Web Fusion PHP Limits
    • Meta Title Tag and SEO
    • Ecommerce Back Office Optimisations
    • Purashop : SEO Services
    • Regular Expression Test Tool
    • File Comparison on Ubuntu
    • Favourite Firefox Extensions
    • Who Needs Photoshop? PHP GD Images and Your Online Store

Edmonds Commerce related questions? Send us a message or call us on 0844 357 0201.

Freelance PHP Web Design UK Commercial Web Design