PHP code example of tubalmartin / cssmin
1. Go to this page and download the library: Download tubalmartin/cssmin library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tubalmartin / cssmin example snippets
ubalmartin\CssMin\Minifier as CSSmin;
// Use it!
$compressor = new CSSmin;
// Autoload libraries
fier as CSSmin;
// Extract the CSS code you want to compress from your CSS files
$input_css = file_get_contents('test.css');
// Create a new CSSmin object.
// By default CSSmin will try to raise PHP settings.
// If you don't want CSSmin to raise the PHP settings pass FALSE to
// the constructor i.e. $compressor = new CSSmin(false);
$compressor = new CSSmin;
// Set the compressor up before compressing (global setup):
// Keep sourcemap comment in the output.
// Default behavior removes it.
$compressor->keepSourceMapComment();
// Remove important comments from output.
$compressor->removeImportantComments();
// Split long lines in the output approximately every 1000 chars.
$compressor->setLineBreakPosition(1000);
// Override any PHP configuration options before calling run() (optional)
$compressor->setMemoryLimit('256M');
$compressor->setMaxExecutionTime(120);
$compressor->setPcreBacktrackLimit(3000000);
$compressor->setPcreRecursionLimit(150000);
// Compress the CSS code!
$output_css = $compressor->run($input_css);
// You can override any setup between runs without having to create another CSSmin object.
// Let's say you want to remove the sourcemap comment from the output and
// disable splitting long lines in the output.
// You can achieve that using the methods `keepSourceMap` and `setLineBreakPosition`:
$compressor->keepSourceMapComment(false);
$compressor->setLineBreakPosition(0);
$output_css = $compressor->run($input_css);
// Do whatever you need with the compressed CSS code
echo $output_css;