Recently I from thinkphp ' Runtime_allinone ' learn from the experience: not afraid of the cache more, just afraid of the call chaos, simply will all the commonly used documents merged into a file, not beautiful ...
Copy Code code as follows:
function Strip_whitespace ($content) {
$stripStr = ';
Analyze 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 annotations
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 of <<<eot (Heredoc) in the Php_strip_whitespace system, which cannot correctly understand the space function.
How to use
Copy Code code as follows:
$str = Strip_whitespace (' <?php '. $str);
The front must stitching this, I also do not understand, do not splice the result of the execution generated is the result of the error
Php_strip_whitespace
String Php_strip_whitespace (String$filename)
If it is only a single file and there is no heredoc, it is recommended to use the shortcut
Php_strip_whitespaceFunction