PHP Debug using the browser console
When we debug the PHP program, it is common to print the variable information to the browser, for example:
';p rint_r ($bar); Echo '
'; exit;
However, direct printing may interfere with your page, disrupt layout, and affect the data returned as an API. At this point we can take the debug information output to a file, the following is the simplest example:
Error_log (Print_r ($bar, true));
However, this way to record the log is also appropriate, the use of debugging is still not very convenient. At this point we can use the modern browser console, such as the Chrome console (win shortcut key Ctrl+shift+j), the content output to the console, you can solve the problem.
Now there are some such tools, such as php-console or Chrome Logger, which is for PHP, which supports a variety of server-side languages, using a Chrome extension first, and then providing a server-side library for invocation. The way to achieve this is to use session,cookies and so on to pass data.
As above is a more perfect solution, all provide a wealth of features. But if you just want a simple, usable way to fix the problem without installing the extension, then you can do it:
console.log () function output information to the console, such as the method printed out is a string form, if the single quotation marks, the PHP array and object will be a JS object to print out, that is, echo (""); Which one to use to see the way you like it.As above is the simplest way to achieve, but it is not very good to do so, is the output is very messy, if you call the function in different locations, then the page will be inserted in various positions '; } Return self:: $output; }}
Note as used on