DiDom\Element::count PHP Method

count() public method

Counts nodes for a given XPath expression or a CSS selector.
public count ( string $expression, string $type = Query::TYPE_CSS ) : integer
$expression string XPath expression or CSS selector
$type string The type of the expression
return integer
    public function count($expression, $type = Query::TYPE_CSS)
    {
        return $this->toDocument()->count($expression, $type);
    }

Usage Example

Esempio n. 1
0
 public function testCount()
 {
     $html = '<ul><li>One</li><li>Two</li><li>Three</li></ul>';
     $document = new Document($html, false);
     $list = $document->first('ul');
     $this->assertEquals(3, $list->count('li'));
     $document = new Element('ul');
     $this->assertEquals(0, $document->count('li'));
 }