1. Go to this page and download the library: Download tbela99/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/ */
use \TBela\CSS\Parser;
use \TBela\CSS\Renderer;
$parser = new Parser($css);
$element = $parser->parse();
// append an existing css file
$parser->append('https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css');
// append css string
$parser->appendContent($css_string);
// pretty print css
$css = (string) $element;
// minified output
$renderer = new Renderer([
'compress' => true,
'convert_color' => 'hex',
'css_level' => 4,
'sourcemap' => true,
'allow_duplicate_declarations' => false
]);
// fast
$css = $renderer->renderAst($parser);
// or
$css = $renderer->renderAst($parser->getAst());
// slow
$css = $renderer->render($element);
// generate sourcemap -> css/all.css.map
$renderer->save($element, 'css/all.css');
// save as json
file_put_contents('style.json', json_encode($element));
use \TBela\CSS\Renderer;
// fastest way to render css
$beautify = (new Renderer())->renderAst($parser->setContent($css)->getAst());
// or
$beautify = (new Renderer())->renderAst($parser->setContent($css));
// or
$css = (new Renderer())->renderAst(json_decode(file_get_contents('style.json')));
$renderer = new Renderer([
'sourcemap' => true
]);
// call save and specify the file name
// generate sourcemap -> css/all.css.map
$renderer->save($element, 'css/all.css');
use \TBela\CSS\Parser;
$parser = new Parser();
$parser->setContent($css);
$stylesheet = $parser->parse();
// get @font-face nodes by class names
$nodes = $stylesheet->queryByClassNames('@font-face, .foo .bar');
// or
// get all src properties in a @font-face rule
$nodes = $stylesheet->query('@font-face/src');
echo implode("\n", array_map('trim', $nodes));
use \TBela\CSS\Element\Parser;
use \TBela\CSS\Element\Renderer;
$parser = new Parser($css);
// parse and render
echo (string) $parser;
// or render minified css
$renderer = new Renderer(['compress' => true]);
echo $renderer->renderAst($parser);
# or
echo $renderer->renderAst($parser->getAst());
# or
// slower - will build a stylesheet object
echo $renderer->render($parser->parse());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.