How to remove PHP comment spaces from PHP files
This article mainly introduces the PHP file how to remove the PHP comment space, the article is very detailed, has a certain reference value, interested friends must read it!
Recently, I learned from thinkphp's' RUNTIME_ALLINONE': I'm not afraid of too many caches, but I'm afraid of calling too much. Wouldn't it be beautiful to merge all the commonly used files into one file?
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; $iTunes +) {
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
}
The custom function effectively solves the problem that the built-in unannotated space function in php_strip_whitespace system can not be understood correctly.