Using the browser console (console) to progress PHP Debug

Source: Internet
Author: User
Tags php debug
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.