PHP Classes

Simple PHP CSS Parser: Parse CSS stylesheets and edit CSS styles

Recommend this page to a friend!
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 537 This week: 3All time: 5,607 This week: 44Up
Version License PHP version Categories
simple-css-parser 1.0.0BSD License5HTML, PHP 5, Parsers
Description 

Author

This class can parse CSS stylesheets and edit CSS styles.

It can take a given CSS file or string and parse it to extract the style definitions.

The class can also search for style definitions, add, change or remove styles or properties, and saved the stylesheet back to a file or string.

Innovation Award
PHP Programming Innovation award nominee
June 2015
Number 5


Prize: PhpStorm IDE personal permanent license
Many sites generate CSS stylesheets dynamically to address needs of specific browsers or other circumstances.

This class can take a given CSS stylesheet file and modify it dynamically by adding, changing or removing styles and property definitions.

Manuel Lemos
Picture of intekhab rizvi
  Performance   Level  
Name: intekhab rizvi <contact>
Classes: 1 package by
Country: India India
Age: 36
All time rank: 3196208 in India India
Week rank: 52 Up4 in India India Up
Innovation award
Innovation award
Nominee: 1x

Details

Simple PHP CSS Parser

Simple PHP CSS Parser: A Parser to read and alter css contents using PHP or Codeigniter

It is a very simple CSS parser based on PHP, its read CSS file as well as CSS string and make a parsed PHP array.

This class comes with all the functions necessary to make searching, alteration, addition and removal of any thing inside css file or string easily and putting it back everything as a complete css codes to css file dynamically or exporting as a string back to program.

This class is ready to use in your PHP based project as well as Codeigniter v2 or v3 framework. Just initialize the class in PHP core project or load as library into Codeigniter framework.

Installation

Core PHP

1) require('Cssparser.php');

2) $css = new Cssparser();

Codeigniter

1) put the Cssparser.php file into application/libraries folder of codeigniter.

2) Inside any controller, load it as a normal library

 $this->load->library('cssparser');
 

3) $this->cssparser->read_from_file($folder."/css/custom.css");

Methods

  • `read_from_file` : Read css file and build PHP Array `$css->read_from_file('myfolder/myfile.css');`
  • `read_from_string` : Read css using string and build PHP Array `$css->read_from_string('html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}');`
  • `find_parent` : Find a CSS using css rule selector E.g `$css->find('#wrapper');` or `$css->find('.wrapper');`
  • `find_parent_by_property` : Find a css rule using css property E.g `$css->find_parent_by_property('background-color');`
  • `find_parent_by_value` : Find a css rule using css property value E.g `$css->find_parent_by_value('350px');`
  • `find_property_value_pair` : Find a css rule using css property value pair E.g `$css->find_property_value_pair('background-color','#FFF');`
  • `add_parent` : Add a new css rule with its css property and value E.g `$css->add_parent('#bodywrapper', array('background-color'=>'#FFF'));`
  • `remove_parent` : Remove any css rule E.g `$css->remove_parent('#bodywrapper');`
  • `rename_parent` : Rename any css rule E.g `$css->rename_parent('#bodywrapper');`
  • `add_property` : Add new css property into css rule E.g `$css->add_property('#bodywrapper', 'max-width', '100px', true);` Passing `true` in the 4th parameter will all class to create new parent css rule if already not exsist into the current parsed css array, passing `false` will return false if parent not found into the PHP Array.
  • `update_property` : Update already exsisted css property inside any css rule E.g `$css->update_property('#bodywrapper', 'max-width', '600px');`
  • `remove_property` : Remove already exsisted css property from any css rule E.g `$css->remove_property('#bodywrapper', 'max-width');`
  • `export_css` : Export css rule as a string, this will incude all of the changes you have done till now on css `$css->export_css();`
  • `save` : Save the entire css codes into the same css file passed on `read_from_file` function E.g `$css->save();`

  Files folder image Files  
File Role Description
Plain text file Cssparser.php Class PHP Class
Accessible without login Plain text file LICENSE Lic. license
Accessible without login Plain text file README.md Doc. readme

 Version Control Unique User Downloads Download Rankings  
 100%
Total:537
This week:3
All time:5,607
This week:44Up