PEAR logo

HTML_CSS : The Definitive Guide

To File

HTML_CSS::toFile() is probably the most interresting solution. You can create a pure CSS file on the fly.

[Warning] Warning
If file already exists, it will be replace without warning !

This script will load an existing style sheet and replace the body definition :

  1. <?php
  2. require_once 'HTML/CSS.php';
  3.  
  4. $css = new HTML_CSS();
  5.  
  6. $css->parseFile('example.css');
  7.  
  8. $css->setStyle('body', 'background-color', '#0c0c0c');
  9. $css->setStyle('body', 'color', '#ffffff');
  10.  
  11. $css->toFile('example.css');
  12. ?>
HTML_CSS : The Definitive Guide v 1.5.0 : January 15, 2008