PHP source code compression tool _ PHP Tutorial

Source: Internet
Author: User
Tags php download
PHP source code compression tool. Usage: (run on the command line) copy the code as follows: phpcompactor. phpDESTINATION. phpSOURCE. php Download: compactor. php copy the code as follows :#! Usrbinenvphp? Php 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 );
?>

Compile (run in the command line) Code: php compactor. php DESTINATION. php SOURCE. php Download: compactor. php code :#! /Usr/bin/env php? Php...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.