PHP Debug Echo's

15,322

Solution 1

You should try error_log function. It will log your debug output directly into the web server logs, and not in your page.

Another way is to echo between comments markups:

echo '<!-- This is a debug message! -->';

Solution 2

Yes, use the Apache error log, if you have that kind of setup, with tail -f. Use the error_log function found here.

Solution 3

I like to use:

error_log("message and vars here");

It depends on the server configuration, but if you can use it, you get a nice log-file. Very useful.

Solution 4

I typically use this for my debugging purposes.

namespace Debug;

function print_r($var, $return)
{
    $s = '<pre>' . htmlspecialchars(\print_r($var, true)) . '</pre>';
    if ($return) {
        return $s;
    } else {
        echo $s;
    }
}

Solution 5

One of my go-to methods for a quick debug is this:

echo '<pre>';
print_r($variable);
echo '</pre>';
die;

However, if you're really looking into getting a lot of good data from your application, check out http://xdebug.org/

Share:
15,322
Chud37
Author by

Chud37

I am a 30 year old programmer living and working in the UK. I use PHP, jQuery and SQL. I build and maintain several websites for my job.

Updated on August 12, 2022

Comments

  • Chud37
    Chud37 almost 2 years

    Just wondering -

    When debuging PHP - how do you like to output the test data to see whats going on? I've been noticing that alot of my PHP echo testing is screwing with my CSS. Does anyone have a good clean method of seeing the results without screwing with the site itself?