All PHP file packages remove all comments in one PHP file remove extra spaces keep output pure PHP (that is, no additional processing steps are required to parse the file) usage: (run on the command line)
The code is as follows:
Php compactor. php DESTINATION. php SOURCE. php
Download: compactor. php
The code is as follows:
#! /Usr/bin/env php
/**
* Compact PHP code.
*
* Strip comments, combine entire library into one file.
*/
If ($ argc <3 ){
Print "Strip unecessary data from PHP source files. \ n \ tUsage: php compactor. php DESTINATION. php SOURCE. php ";
Exit;
}
$ Source = $ argv [2];
$ Target = $ argv [1];
Print "Compacting $ source into $ target. \ n ";
Include $ source;
$ Files = get_included_files ();
Print_r ($ files );
$ Out = fopen ($ target, 'w ');
Fwrite ($ out ,' Fwrite ($ out, '// QueryPath. Copyright (c) 2009, Matt Butcher.'. PHP_EOL );
Fwrite ($ out, '// This software is released under the LGPL, v. 2.1 or an MIT-style license.'. PHP_EOL );
Fwrite ($ out, '// http://opensource.org/licenses/lgpl-2.1.php ');
Fwrite ($ out, '// http://querypath.org.'. PHP_EOL );
Foreach ($ files as $ f ){
If ($ f! ==__ FILE __){
$ Contents = file_get_contents ($ f );
Foreach (token_get_all ($ contents) as $ token ){
If (is_string ($ token )){
Fwrite ($ out, $ token );
}
Else {
Switch ($ token [0]) {
Case T_REQUIRE:
Case T_REQUIRE_ONCE:
Case T_INCLUDE_ONCE:
// We leave T_INCLUDE since it is rarely used to include
// Libraries and often used to include HTML/template files.
Case T_COMMENT:
Case T_DOC_COMMENT:
Case T_OPEN_TAG:
Case T_CLOSE_TAG:
Break;
Case T_WHITESPACE:
Fwrite ($ out ,'');
Break;
Default:
Fwrite ($ out, $ token [1]);
}
}
}
}
}
Fclose ($ out );
?>