Provides various official and user-released code examples and code reference. You are welcome to exchange and learn about the built-in PHP code
Php_strip_whitespaceThis method is used to read the PHP file and remove the blank and comments in the code, but does not support directly reading the content to remove the blank and comments. The following method supports reading the string content, the ThinkPHP framework also has the built-in method.
/**
* Remove blank and comments from the code
* @ Param string $ content Code content
* @ Return string
*/
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;
Case T_START_HEREDOC:
$ StripStr. = "< Break;
Case T_END_HEREDOC:
$ StripStr. = "THINK; \ n ";
For ($ k = $ I + 1; $ k <$ j; $ k ++ ){
If (is_string ($ tokens [$ k]) & $ tokens [$ k] = ';'){
$ I = $ k;
Break;
} Else if ($ tokens [$ k] [0] = T_CLOSE_TAG ){
Break;
}
}
Break;
Default:
$ Last_space = false;
$ StripStr. = $ tokens [$ I] [1];
}
}
}
Return $ stripStr;
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB