PEAR logo

HTML_CSS : The Definitive Guide

Parse a file contents

Another quick way to create multiple selector definitions in one step is to use the HTML_CSS::parseFile() function. CSS file to load is supposed to be W3C/CSS compliant.

If previous selector definitions was into a file named 'styles.css', then to parse and load contents will be done with such script :

  1. <?php
  2. require_once 'HTML/CSS.php';
  3.  
  4. $css = new HTML_CSS();
  5. $css->parseFile('styles.css');
  6. $css->display();
  7. ?>
[Tip] Tip
If there are duplicate definitions into file contents, you should parse file with call :
  1. <?php
  2. $css->parseFile('styles.css', true);
  3. ?>
We will see next why we may find such duplicate definitions.
HTML_CSS : The Definitive Guide v 1.5.0 : January 15, 2008