PHP文件去掉PHP注释空格的函数分析(PHP代码压缩)
最近我从thinkphp的‘RUNTIME_ALLINONE'借鉴到经验:不怕缓存多,就怕调用乱,索性将所有常用的文件全部合并成一个文件,岂不美哉。。。
复制代码 代码如下:
function strip_whitespace($content) {
$stripStr = '';
//分析php源码
$tokens = token_get_all ($content);
$last_space = false;
for ($i = 0, $j = count ($tokens); $i if (is_string ($tokens[$i])){
$last_space = false;
$stripStr .= $tokens[$i];
}
else{
switch ($tokens[$i][0]){
//过滤各种PHP注释
case T_COMMENT:
case T_DOC_COMMENT:
break;
//过滤空格
case T_WHITESPACE:
if (!$last_space){
$stripStr .= ' ';
$last_space = true;
}
break;
default:
$last_space = false;
$stripStr .= $tokens[$i][1];
}
}
}
return $stripStr;
}
该自定义函数有效解决了php_strip_whitespace系统内置去注释空格函数不能正确理解使用方法
复制代码 代码如下:
$str = strip_whitespace('
前面一定要拼接这个,我也搞不懂,不拼接的话执行生成的结果是错误的结果
php_strip_whitespace
string php_strip_whitespace (string$filename )
如果仅仅是单文件并且没有heredoc的话,还是建议使用快捷的php_strip_whitespace函数

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function