DiDom\Document::has PHP Method

has() public method

Checks the existence of the node.
public has ( string $expression, string $type = Query::TYPE_CSS ) : boolean
$expression string XPath expression or CSS selector
$type string The type of the expression
return boolean
    public function has($expression, $type = Query::TYPE_CSS)
    {
        $xpath = new DOMXPath($this->document);
        $expression = Query::compile($expression, $type);
        $expression = sprintf('count(%s) > 0', $expression);
        return $xpath->evaluate($expression);
    }

Usage Example

Beispiel #1
0
 public function testHas()
 {
     $html = $this->loadFixture('posts.html');
     $document = new Document($html, false);
     $this->assertTrue($document->has('.posts'));
     $this->assertFalse($document->has('.fake'));
 }
All Usage Examples Of DiDom\Document::has