PHP 源代码压缩小工具
作者:bea
使用方法:(在命令行运行) 代码如下: php compactor.php DESTINATION.php SOURCE.php 下载: compactor.php 代码如下: #!/usr/bin/env php <?php /** * Compact PHP code. * * Strip comments, combine entire library into one file. */ if ($argc < 3) { print
使用方法:(在命令行运行)
代码如下:
php compactor.php DESTINATION.php SOURCE.php
下载:
compactor.php
代码如下:
#!/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.
Usage: php compactor.php DESTINATION.php SOURCE.php";
exit;
}
$source = $argv[2];
$target = $argv[1];
print "Compacting $source into $target.
";
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);
?>
有用 | 无用
代码如下:
php compactor.php DESTINATION.php SOURCE.php
下载:
compactor.php
代码如下:
#!/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.
Usage: php compactor.php DESTINATION.php SOURCE.php";
exit;
}
$source = $argv[2];
$target = $argv[1];
print "Compacting $source into $target.
";
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);
?>
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- php 文件上传代码(限制jpg文件)
- php下将XML转换为数组
- PHP 巧用数组降低程序的时间复杂度
- 使用PHP获取网络文件的实现代码
- php中计算时间差的几种方法
- php 操作excel文件的方法小结
- PHP编程过程中需要了解的this,self,parent的区别
- php 学习笔记
- 用php实现让页面只能被百度gogole蜘蛛访问的方法
- PHP类的使用 实例代码讲解
- php 多线程上下文中安全写文件实现代码
- PHP 获取目录下的图片并随机显示的代码
- phpMyAdmin链接MySql错误 个人解决方案
- php 需要掌握的东西 不做浮躁的人
- php 文章采集正则代码
- PHP array_push 数组函数
- PHP simple_html_dom.php+正则 采集文章代码
- 在PHP中检查PHP文件是否有语法错误的方法
- php 常用类整理