How to use: (Run at the command line)
Copy Code code as follows:
PHP compactor.php destination.php source.php
Download: compactor.php
Copy Code code as follows:
#!/usr/bin/env PHP
<?php
/**
* Compact PHP code.
*
* Strip comments, combine entire library into one file.
*/
if ($ARGC < 3) {
Print "Strip unecessary data from PHP source files.\n\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, ' <?php '. PHP_EOL);
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);
?>