Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

sabberworm/php-css-parser 8.5.0

Parser for CSS Files written in PHP
Package summary
Share
0
issues
0
licenses
Package created
2 Aug 2012
Version published
1 Feb 2024
Maintainers
3
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does sabberworm/php-css-parser do?

The sabberworm/php-css-parser is a PHP library that provides a comprehensive parsing solution for CSS files. It allows developers to read CSS files into a data structure that can be manipulated and output as optimized CSS. This makes it possible to work with CSS files programmatically, offering a high degree of control and flexibility.

How do you use sabberworm/php-css-parser?

To make use of the sabberworm/php-css-parser, you need to first install it via Composer using the command composer require sabberworm/php-css-parser. Once installed, you can create a new instance of the Parser and read a file using example code like the one below:

$parser = new \Sabberworm\CSS\Parser(file_get_contents('somefile.css'));
$cssDocument = $parser->parse();

The resulting CSS document structure can then be manipulated prior to being output. There are settings to control character sets, enable strict parsing, and disable multibyte functions. Here's a code snippet showing how to manipulate the CSS.

$myId = "#my_id";
$parser = new \Sabberworm\CSS\Parser($css);
$cssDocument = $parser->parse();
foreach ($cssDocument->getAllDeclarationBlocks() as $block) {
    foreach ($block->getSelectors() as $selector) {
        $selector->setSelector($myId.' '.$selector->getSelector());
    }
}

Finally, you can output the CSS by using the render() method:

print $cssDocument->render();

This can be formatted using an instance of type \Sabberworm\CSS\OutputFormat.

Where are the sabberworm/php-css-parser docs?

The sabberworm/php-css-parser docs are contained within its README file on the project's GitHub page. The README includes a detailed explanation of how to use the library, code usage examples, and an overview of its structure and features. Developers looking to integrate this library into their projects will find the README a comprehensive resource for understanding how to effectively leverage the power of sabberworm/php-css-parser.