php合并为一个文件,PHP-合并php文件

前两天刚做的功能,希望对你有所帮助 ,我把所有文件压缩合并了,去注释,去空格。。你懂的

/**

* 编译框架核心文件

*

*/

private function build_runtime() {

$run_time = $this->_app_config ['Cache_Dir'] . '/~runtime.php';

$is_cache = $this->_app_config ['Cache_Runtime'];

if ($is_cache && file_exists ( $run_time )) {

include_once $run_time;

return;

}

//获取导入列表

$autoImport = include dirname ( __FILE__ ) . '/YautoImport.php';

//导入核心

foreach ( $autoImport as $file ) {

require $this->_app_config ['FrameWork_Dir'] . '/' . $file;

}

if ($is_cache) {

$content = '<?php ';

foreach ( $autoImport as $file ) {

$file = $this->_app_config ['FrameWork_Dir'] . '/' . $file;

$get = trim ( file_get_contents ( $file ) );

$get = substr ( $get, 5 );

if ('?>' == substr ( $get, - 2 )) {

$get = substr ( $get, 0, - 2 );

}

$content .= $get;

}

$content = $this->strip_space ( $content );

file_put_contents ( $run_time, $content );

unset ( $content );

}

}

/**

* 压缩PHP代码 (去除注释 ,空格 , 换行, TAB)

*

* @param unknown_type $content

* @return unknown

*/

function strip_space($content) {

//php_strip_whitespace 函数也可去除 PHP 文件中的注释

$stripStr = null;

$space = false; //记录上个字符是否为空

$tokens = token_get_all ( $content );

foreach ( $tokens as $value ) {

if (is_string ( $value )) {

$stripStr .= $value;

$space = false;

} else {

switch ($value [0]) {

case T_COMMENT : //单行注释

case T_DOC_COMMENT : //文档注释

break;

case T_WHITESPACE : //空格、换行、Tab...

if (! $space)

$stripStr .= ' ';

$space = true;

break;

default :

$stripStr .= rtrim ( $value [1] ); //加 trim 主要是去掉 <?php 后面的空

$space = false;

}

}

}

return $stripStr;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值