PhpMinify

PhpMinify

PhpMinify is a tool that can be used to minify the size of PHP scripts.

  • Language: PHP
  • Released: Nov 14, 2011
    Last Update: Nov 13, 2011

Please note that this will NOT make files faster to execute, the only reason why you might want to use it is to distribute smaller files or to remove comments.

Hide

Basic Usage

Here is the basic usage:

<?php
require_once( dirname(dirname(__FILE__)) . '/library/PhpMinify.php' );

try {
    $minifier = new PhpMinify();
    $minifier->run();
} catch (PhpMinify_Exception $ex) {
    echo 'ERROR: ' . $ex->getMessage();
}
?>

Note: A similar script already exists in the tests/ directory in the package. You can just put your input files in the tests/input/ directory and run the index.php file. It will minify all PHP files and put the results in tests/output/ directory.

Hide

Requirements

  • PHP 5
Hide

Features

  • Support for subdirectories
  • Support for patterns to skip
Hide

Configuration

Options are given to the constructor like this:

<?php
$options = array(
    // input path, it should be absolute
    PhpMinify::OPT_INPUT_PATH => dirname(__FILE__) . '/input/',
    // output path, it should be absolute
    PhpMinify::OPT_OUTPUT_PATH => dirname(__FILE__) . '/output/',
    // input patterns to match, any of the  patterns must be matched in order to minify
    // items are defined as input parameters for preg_match()
    PhpMinify::OPT_INPUT_PATTERNS => array('/\.php$/'),
    // skip patterns to match, if any of the  patterns must be matched, the target is skipped
    // items are defined as input parameters for preg_match()
    PhpMinify::OPT_SKIP_PATTERNS => array('/^\./'),
    // track the list of minified files, disable if there are too many files and don't care which files were minified
    PhpMinify::OPT_TRACK_MINIFIED => true,
    // strip tabulation, this CAN change the value of multiline strings from code, by default it's disabled
    PhpMinify::OPT_STRIP_TABULATION => false
);

try {
    $minifier = new PhpMinify($options);
    $minifier->run();
} catch (PhpMinify_Exception $ex) {
    echo 'ERROR: ' . $ex->getMessage();
}
?>
Hide

Documentation

Please see the PhpMinify documentation.

You need to log-in or create an account
  • Create an account
  • Log-in
Please use your real name.
Activation link will be sent to this address.
Minimum 8 characters
Enter your password again

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

X

Save your watchlist

Fill your details below to receive project updates from your watch list - including new versions, price changes and discounts.

I agree to the terms of use and privacy policy.

2 licenses, starting from From » FREE 14 day money-back guarantee View Licenses
or Get a quote

for customization or integration services

  • Easy to use, but failed to impress as it does not work if you just want to remove comments from your source code. Also the minification is not of any high quality.
    SR Samnan ur Rehmnan
    3 years ago, 0 comments
    Was this helpful?
    Flag 0 of 1 people found this review helpful
  • very useful . helps secure a lot of my projects source code :)
    BS Badea Sorin
    3 years ago, 0 comments
    Was this helpful?
    Flag
  • Very cool
    T t9liu
    3 years ago, 0 comments
    Was this helpful?
    Flag
Post a comment

Or enter your name and Email
  • t9liu 3 years ago
    I think it's quite cool and very useful for our project. Thx
  • DP Daniel Paul 3 years ago
    Nice :)