PEAR logo

HTML_CSS : The Definitive Guide

Parse multi data sources

We have already seen two single sources where CSS data could come from. The last one allow to parse data from multiple sources at once. HTML_CSS::parseData() function take an array as first argument. Each item is either a filename (with .css extension) or a string. Each source is merge to produce at end a unique style sheet.

In script below we load selector definitions from two independent sources: a string and a css file which contents duplicate definitions (parseFile() 2nd argument to set to true to catch this situation; see next section for explains). Internet Explorer).

  1. <?php
  2. require_once 'HTML/CSS.php';
  3.  
  4. $css = new HTML_CSS();
  5.  
  6. // 1. a string to parse
  7. $strcss = '
  8. body, p { background-color: white; font: 1.2em Arial; }
  9. p, div#black { color: black; }
  10. div{ color: green; }
  11. p { margin-left: 3em; }
  12. ';
  13. $css->parseString($strcss);
  14.  
  15. // 2. a css file with duplicate definitions
  16. $css->parseFile('iehack.css', true);
  17.  
  18. $css->display();
  19. ?>
HTML_CSS : The Definitive Guide v 1.5.0 : January 15, 2008