Home >Backend Development >PHP Tutorial >[php] Let Notepad become your console for controlling variables
php is not like aspx and jsp. The development environment of aspx and jsp is stuck, but they have a console of Visual Studio and Eclipse to check the changes of variables at any time. If php is developed using Notepad, Notepad or Dreamweaver, etc., There is no console for you to observe the flow of variables. In some background pages, such as Ajax response pages, such as database method pages, for example, if you want to see whether a certain variable is requested, there is no page for you to echo at all.
At this time, there is no need to install any tools at all. Use PHP statements to operate files and print the variables or data to be debugged to a txt or an html. We can open or refresh without listening to observe the variables, which is enough for debugging. .
If you want to debug the $content variable, write like this:
$fp = fopen('./a.txt', 'a+b'); fwrite($fp, "content=".$content); fclose($fp);means to create an a.txt under the same directory of this page. Of course, if you are unhappy, you can also write it to c:/ or somewhere else, or even You can output to ./a.html, then open a browser, output and view it once, and watch it non-stop, which has achieved the effect of rapid debugging. If a.txt already exists, and a.txt has content, then in this a. Things are written at the end of the .txt file. This is the meaning of the 'a+b' parameter.
Then, write the "content=".$content variable, this string into the file a.txt. Of course, you can output it however you like. Of course, this output will not be carried back to the carriage. You can also Add a carriage return after the variable. See the result picture below for details.
Close this pointer afterwards.
If the thing you want to debug is a $content array, then write like this:
$fp = fopen('./a.txt', 'a+b'); fwrite($fp, print_r($content, true)); fclose($fp);where: print_r() can simply print out strings and numbers, while the array is displayed as a bracketed list of keys and values. , and starts with Array. But the results of print_r() outputting Boolean values and NULL are meaningless, because they all print "n". Therefore, using the var_dump() function is more suitable for debugging.
The following is part of my debugging results of a certain program. After the 2 and 4 variables
is an array:
The above has introduced how [php] allows Notepad to become a console for you to control variables, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.