PHP Classes

File: classes/css-parser/filters/css-class-filter.php

Recommend this page to a friend!
  Classes of Gonzalo Chumillas   PHP CSS Parser   classes/css-parser/filters/css-class-filter.php   Download  
File: classes/css-parser/filters/css-class-filter.php
Role: Class source
Content type: text/plain
Description: CSSClassFilter class
Class: PHP CSS Parser
Get HTML document nodes matching a CSS selector
Author: By
Last change: Merge branch 'master' of https://github.com/cequiel/cssparser
update
Date: 10 years ago
Size: 1,059 bytes
 

Contents

Class file image Download
<?php
require_once dirname(dirname(__DIR__)) . "/css-parser/filters/css-filter.php";

class
CSSClassFilter extends CSSFilter {
   
/**
     * Class name.
     * @var string
     */
   
private $class_name;
   
   
/**
     * @param string $class_name
     */
   
public function __construct($class_name) {
       
$this->class_name = $class_name;
    }
   
   
/**
     * Is the class in the list?
     * @param string $class
     * @param string $classes
     * @return boolean
     */
   
private function isClassInList($class, $classes) {
       
$items = explode(" ", trim($classes));
        if (
count($items) > 0) {
            foreach (
$items as $item) {
                if (
strcasecmp($class, trim($item)) == 0) {
                    return
TRUE;
                }
            }
        }
        return
FALSE;
    }
   
   
/**
     * Does the node match?
     * @param DOMElement $node
     * @return boolean
     */
   
public function match($node) {
        return
$this->isClassInList($this->class_name, $node->getAttribute("class"));
    }
}