Function analysis (PHP code compression) with PHP comments and spaces removed from the PHP file ). Recently, I have learned from thinkphp's 'runtime _ ALLINONE: I am afraid that the cache is not large, so I am afraid that the call is messy. simply merge all commonly used files into one file... Recently, I have learned from thinkphp's 'runtime _ ALLINONE 'experience: I am afraid that the cache is not large, so I am afraid of calling chaos. I simply merge all the commonly used files into one file, not beautiful...
The code is as follows:
Function strip_whitespace ($ content ){
$ StripStr = '';
// Analyze the php source code
$ Tokens = token_get_all ($ content );
$ Last_space = false;
For ($ I = 0, $ j = count ($ tokens); $ I <$ j; $ I ++ ){
If (is_string ($ tokens [$ I]) {
$ Last_space = false;
$ StripStr. = $ tokens [$ I];
}
Else {
Switch ($ tokens [$ I] [0]) {
// Filter various PHP comments
Case T_COMMENT:
Case T_DOC_COMMENT:
Break;
// Filter spaces
Case T_WHITESPACE:
If (! $ Last_space ){
$ StripStr. = '';
$ Last_space = true;
}
Break;
Default:
$ Last_space = false;
$ StripStr. = $ tokens [$ I] [1];
}
}
}
Return $ stripStr;
}
This user-defined function effectively solves the problem that php_strip_whitespace does not properly understand the built-in uncomment space function. <
Usage
The code is as follows:
$ Str = strip_whitespace ('
We have to splice this before. I don't understand it either. if we don't splice it, the result generated by executing the command is incorrect.
Php_strip_whitespace
String php_strip_whitespace (string $ filename)
If only a single file does not have heredoc, it is recommended to use quick
Php_strip_whitespaceFunction
Bytes... Copy...