Zend - The PHP Company




Miscellaneous

Add Code


Helper function for debugging scripts  

Type: code fragment
Added by: lecuanda
Entered: 19/07/2001
Last modified: 07/12/2000
Rating: - (fewer than 3 votes)
Views: 4511
This little function will help you debug scripts, specially if you use a lot of objects and arrays. it prints a beautified version of the 'print_r' output.

if you add this function to your script, just call your script adding ?debug=1 (script.php?debug=1)or add the $debug global variable set to true to see the debugging output


<?php
function dp($call,$cname) {
    global 
$debug;
    if (
$debug) {
        echo 
$cname.":<pre>";
        if (!
is_array($call) or !is_object($call) or !is_resource($call)) { 
            
$call=htmlspecialchars($call); 
        }
        
print_r($call);
        if ( 
is_array($call)) { reset($call); }
        echo 
"</pre><hr>";    
    }
// end function dp() 
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories