PHP code example of webzille / cssparser

1. Go to this page and download the library: Download webzille/cssparser 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/ */

    

webzille / cssparser example snippets


$parser = new Parser("stylesheet.css");
$nodes = $parser->parse()->getNodes();

$format = (new CssFormat)->setIndent("    ")->setNewLine("\n");
$render = new Render($nodes, $format);
$css = trim($render->css());

$render = new Render($nodes);
$css = trim($render->css());

$minified = true;
$format = (new CssFormat)->minify($minified);
$render = new Render($nodes, $format);
$css = trim($render->css());

// The following is the same as the previous
$format = (new CssFormat)->minify();
$render = new Render($nodes, $format);
$css = trim($render->css());

$parser = new Parser("stylesheet.css");
$nodes = $parser->parse()->getNodes();

// VS
$nodes = CSS::parser("stylesheet.css")->parse()->getNodes();

$format = (new Format)->minify();

// VS
$format = CSS::format()->minify();

$optimize = CSS::optimize($nodes)->removeDuplicates(); // And other chained methods if you need them
$search = CSS::search($nodes)->searchByType(Selector::class);

$css = CSS::render($optimize->getNodes(), $format)->css();

$search = CSS::search($nodes);

// Or the following if you prefer
$search = new Search($nodes);

$search->searchByType(Comment::class);

$criteria = [
    [
        'type'  => 'type',
        'value' => \Webzille\CssParser\Nodes\AtRule::class
    ],
    [
        'type'      => 'property',
        'property'  => 'font-family',
        'value'     => 'MyFont'
    ],
    [
        'type'  => 'selector',
        'value' => '.container'
    ]
];

$search = CSS::search($nodes)->find($criteria);

$results = $search->results();

$optimizer = CSS::optimize($nodes);

// Or the following if you prefer or not going to chain any methods to it.
$optimizer = new Optimize($nodes);