' == substr($content, -2)) $content = substr($content, 0, -2); return $content; } /** * 压缩PHP代码 * * @param string $content 压缩内容 * @return string */ function compress_code($content) { $strip_str = ''; //分析php源码 $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; $strip_str .= $tokens[$i]; } else { switch ($tokens[$i][0]) { //过滤各种PHP注释 case T_COMMENT: case T_DOC_COMMENT: break; //过滤空格 case T_WHITESPACE: if (!$last_space) { $strip_str .= ' '; $last_space = true; } break; default: $last_space = false; $strip_str .= $tokens[$i][1]; } } } return $strip_str; } ?>