开发者

Using PHP minify (link provided), how can ALL comments be suppressed/removed?

Using PHP minify (http://code.google.com/p/minify/) how can A开发者_StackOverflowLL comments be suppressed/removed from the end result of the minification? At present all comments in javascript files of the format (any number of lines):

/*
 * 
 * comments...
 * 
 */

Are not being removed and appear in the final minified result (despite the code being minified successfully)..

Any help would be much appreciated!


Try the token_get_all()...

<?php

$sampleCode = "
<?php
/**
 * This is a comment
 */
function foo() {
    $x = 1;
    $y = $x + 1;
    return $y;
}
";


$tokens = token_get_all($sampleCode);
$cleanedCode = "";
foreach ($tokens as $token) {
    if (is_array($token)) {
        if ($token[0] != T_COMMENT && $token[0] != T_DOC_COMMENT) {
            $cleanedCode .= $token[1];
        }
    } else {
        $cleanedCode .= $token;
    }

}


?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜