Ec (2 );#! Usrbinenvphp & lt ;? Php *** CompactPHPcode. *** Stripcomments, combineentirelibrarypoliconefile. * if ($ argc & lt; 3) {print & quot; StripunecessarydatafromPHPsour script ec (2); script
#! /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. nntUsage: 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 );
?>