Find definitions

Find definitions – searching for selectors and properties

In brief

One of features of HTML_CSS that was still missing to version less or equal than 1.0.1 is ability to detect if a selector (or group of selectors), and/or a property (or group of properties) was already defined. This is now possible with method : HTML_CSS::grepStyle()

Searching for a group of selectors

Let creates these definitions into progress2.css file :

#PB1.cellPB1I, #PB1.cellPB1A {
  width: 15px;
  height: 20px;
  font-family: Courier, Verdana;
  font-size: 8px;
  float: left;
}

#PB1.progressBorderPB1 {
  width: 172px;
  height: 24px;
  border-width: 1px;
  border-style: solid;
  border-color: #404040 #dfdfdf #dfdfdf #404040;
  background-color: #CCCCCC;
}

.progressPercentLabelpct1PB1 {
  width: 50px;
  text-align: right;
  background-color: transparent;
  font-size: 11px;
  font-family: Verdana, Tahoma, Arial;
  font-weight: normal;
  color: #000000;
}

.progressTextLabeltxt1PB1 {
  text-align: left;
  background-color: transparent;
  font-size: 11px;
  font-family: Verdana, Tahoma, Arial;
  font-weight: normal;
  color: #000000;
}

.cellPB1I {
  background-color: #CCCCCC;
}

.cellPB1A {
  background-color: #0033FF;
}

body {
    background-color: #E0E0E0;
    color: #000000;
    font-family: Verdana, Arial;
}

Very easy with such script to find where is declared #PB1 class selectors (names like).

<?php
require_once 'HTML/CSS.php';

$css = new HTML_CSS();
$css->parseFile('progress2.css');

// find all selectors beginning with #PB1
$styles $css->grepStyle('/^#PB1/');
echo 
'<pre>'var_dump($styles); echo '</pre>';
?>

Searching for selectors that set a property

We still used the CSS definitions of previous example, identified by progress2.css file :

Very easy with such script to find where is declared color property.

<?php
require_once 'HTML/CSS.php';

$css = new HTML_CSS();
$css->parseFile('progress2.css');

// find all selectors that set the color property
$styles $css->grepStyle('/./''/^color$/');
echo 
'<pre>'var_dump($styles); echo '</pre>';
?>
getting results in different format (Previous) Reference guide (Next)
Last updated: Sat, 22 Nov 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.