1. Go to this page and download the library: Download csstool/css 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/ */
csstool / css example snippets
// Include the autoloader or the classes files
te an instanece of CSSTool\CSS class
$CSS = new CSS;
// Load the initial CSS from a file
$CSS->load('assets/css/css1.css');
// Load another CSS file, appending to the previous CSS
$CSS->load('assets/css/css2.css');
// Saves the final merged and optimized CSS into a file
if($CSS->save('assets/css/optimized.min.css')){
echo 'Saved with sucess!';
} else {
echo 'Something went wrong...';
}
$CSS = new CSSTool\CSS;
// Set an initial CSS from string
$CSS->set('body{color:#333}');
echo $CSS->get('string');
$CSS = new CSSTool\CSS;
// Set an initial CSS from array
$rule = array(
'body' => array('color' => '#333')
);
$CSS->set($rule);
echo $CSS->get('string');
$CSS = new CSSTool\CSS;
// Load CSS from a file
$CSS->load('tests/example.css');
echo $CSS->get('string');
$CSS = new CSSTool\CSS;
// Load CSS from a file
$CSS->load('https://localhost/tests/example.css');
echo $CSS->get('string');
$CSS = new CSSTool\CSS;
$CSS->set('body{color:#333}');
// Create a optimized file
if($CSS->save('tests/css/example-min.css')){
echo 'File created with success';
} else {
echo 'Something went wrong...';
}
$CSS = new CSSTool\CSS;
// string with CSS
$stringCSS = 'body {color:red;} p {margin:0}';
// Array with parsed CSS
$parsedCSS = $CSS->parse($stringCSS);
var_dump($parsedCSS);
$CSS = new CSSTool\CSS;
// Set initial CSS
$CSS->set('body{color:#333333;}');
// Add rule to the end of the CSS
$CSS->append(array(
'p' => array('color'=>'#222222'),
));
echo $CSS->get('string');
$CSS = new CSSTool\CSS;
// Set initial CSS
$CSS->set('body{color:#333333;}');
// Add rule to the beginning of the CSS
$CSS->prepend(array(
'p' => array('color'=>'#222222'),
));
echo $CSS->get('string');
$CSS = new CSSTool\CSS;
$CSS->load('tests/example.css');
// Output as an array
echo $CSS->get();
$CSS = new CSSTool\CSS;
$CSS->load('tests/example.css');
// Output as a string
echo $CSS->get('string');
$CSS = new CSSTool\CSS;
$CSS->load('tests/example.css');
// Output a non minified string
echo $CSS->get('string', false);
// Constructor receives the configs
$CSS = new CSSTool\CSS(['autoprefixer'=>false]);