PEAR logo

HTML_CSS : The Definitive Guide

Chapter 3. FAQ - Frequently Asked Questions

3.1. General questions
3.1.1. What does it cost ?
3.1.2. Do you offer support ?
3.1.3. I found a bug, what shall I do ?
3.1.4. What is CSS ?
3.1.5. What is PEAR ?
3.2. How to
3.2.1. I want to use HTML_CSS without PEAR. Is it possible ?
3.2.2. I want to know property value of a selector, but it can not exist

3.1. General questions

3.1.1. What does it cost ?
3.1.2. Do you offer support ?
3.1.3. I found a bug, what shall I do ?
3.1.4. What is CSS ?
3.1.5. What is PEAR ?
3.1.1.

What does it cost ?

You can download and use it for free. But don't delete the copyright notice. You can read terms of the license

3.1.2.

Do you offer support ?

YES if there is no answer in this Guide and if you are ready to share some informations such as : your configuration (platform Win *nix mac, PHP version, PEAR packages installed) and perharps your script.

3.1.3.

I found a bug, what shall I do ?

You can report it with the bug tracker at PEAR.

3.1.4.

What is CSS ?

CSS (an acronym for Cascading Style Sheets) is a simple mechanism for adding style (e.g. fonts, colors, spacing) to Web documents.

HTML_CSS is a PEAR package that provides methods for handling stylesheet declarations.

Version 1.0.0 does not offers yet methods to validate a style sheet.

3.1.5.

What is PEAR ?

PEAR (an acronym for PHP Extension and Application Repository) is a framework and distribution system for reusable PHP components.

Don't forget to read also the PEAR Manual and PEAR FAQ.

3.2. How to

3.2.1. I want to use HTML_CSS without PEAR. Is it possible ?
3.2.2. I want to know property value of a selector, but it can not exist
3.2.1.

I want to use HTML_CSS without PEAR. Is it possible ?

Yes it is. First, you need to download package PEAR::HTML_Common version 1.2 or greater.

Extract content (Common.php file) in same directory HTML/ as CSS.php file.

Last, you should create your own error handler, or disable it. See chapter Error Handler for details.

3.2.2.

I want to know property value of a selector, but it can not exist

With previous release than 1.1.0 it was not possible because HTML_CSS::getStyle() require at least an existing property, or it will return HTML_CSS_ERROR_NO_ELEMENT_PROPERTY.

With new function HTML_CSS::grepStyle() of version 1.1.0, it's now possible.

  1. <?php
  2. require_once 'HTML/CSS.php';
  3.  
  4. function myErrorHandler()
  5. {
  6.     return PEAR_ERROR_PRINT;  // always print all error messages
  7. }
  8.  
  9. $styles = '
  10. h1, h2, h3, h4 { padding: 1em; }
  11. .highlight p, .highlight ul { margin-left: .5em; }
  12. #main p, #main ul { padding-top: 1em; }
  13. ';
  14.  
  15. $prefs = array(
  16.     'push_callback' => 'myErrorHandler',
  17. );
  18. $attribs = null;
  19.  
  20. $css = new HTML_CSS($attribs, $prefs);
  21. $css->parseString($styles);
  22.  
  23. $css->getStyle('.highlight p', 'color');
  24.  
  25. $styles = $css->grepStyle('/highlight/', '/^color$/');
  26. echo '<pre>'; var_dump($styles); echo '</pre>';
  27. ?>
Lines 4-7, 15-17, 20 :

Custom error handler is defined to allow script to continue (print message), when HTML_CSS::getStyle() will raise error at line 23.

Lines 9-13, 21 :

Stylesheet used is :

  1. h1, h2, h3, h4 { padding: 1em; }
  2. .highlight p, .highlight ul { margin-left: .5em; }
  3. #main p, #main ul { padding-top: 1em; }
Lines 23, 25 :

While HTML_CSS::getStyle() will raise error (printed by custom error handler), line 25 will return an empty array with no error raised.

Reason : color property does not exist for .highlight p class selector.

HTML_CSS : The Definitive Guide v 1.5.0 : January 15, 2008