When you log in PHP, or if the Ajax request is wrong, you want to debug. We usually write the information to a specified file
Of Then, according to the corresponding information to deal with the problem.
For example, the author likes to use Ajax to get no data, in the PHP script, add the following section of code
Copy Code code as follows:
$fp = fopen ('./a.txt ', ' a+b ');
Fwrite ($fp, $content);
Fclose ($FP);
However, there is a problem here. That is $content is an array how to do?
You might say, I'm looping output. What if it's a multidimensional array?
I'm just so tired of the need for Debug.
Here you can use Var_export ().
This function returns the structure information about the variable passed to the function, which is similar to the Var_dump (), unlike the
The representation that it returns is a valid PHP code.
You can return the representation of a variable by setting the second argument of the function to TRUE.
Copy Code code as follows:
$fp = fopen ('./a.txt ', ' a+b ');
Fwrite ($fp, Var_export ($content, true));
Fclose ($FP);
AttentionThe second parameter of Var_export () needs to be set to true to indicate that the return value was obtained. Otherwise, direct output.
In addition, if your $content is just an array and does not contain other content
You can also use Print_r ()
Similarly, the second parameter of Print_r () is also set to True
Copy Code code as follows:
$fp = fopen ('./a.txt ', ' a+b ');
Fwrite ($fp, Print_r ($content, true));
Fclose ($FP);