search
Homephp教程php手册PHP文件去掉PHP注释空格的函数分析(PHP代码压缩)

PHP文件去掉PHP注释空格的函数分析(PHP代码压缩)

Jun 13, 2016 am 11:43 AM
phpruntimethinkphpcodefunctionanalyzecompressionremovedocumentCommentofspace

最近我从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函数
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function