QueryPath\CSS\DOMTraverser::find PHP Méthode

find() public méthode

This is the main function for querying the DOM using a CSS selector.
public find ( string $selector )
$selector string The selector.
    public function find($selector)
    {
        // Setup
        $handler = new Selector();
        $parser = new Parser($selector, $handler);
        $parser->parse();
        $this->selector = $handler;
        //$selector = $handler->toArray();
        $found = $this->newMatches();
        foreach ($handler as $selectorGroup) {
            // fprintf(STDOUT, "Selector group.\n");
            // Initialize matches if necessary.
            if ($this->initialized) {
                $candidates = $this->matches;
            } else {
                //if (empty($selectorGroup)) {
                // fprintf(STDOUT, "%s", print_r($handler->toArray(), TRUE));
                //}
                $candidates = $this->initialMatch($selectorGroup[0], $this->matches);
                //$this->initialized = TRUE;
            }
            foreach ($candidates as $candidate) {
                // fprintf(STDOUT, "Testing %s against %s.\n", $candidate->tagName, $selectorGroup[0]);
                if ($this->matchesSelector($candidate, $selectorGroup)) {
                    // $this->debug('Attaching ' . $candidate->nodeName);
                    $found->attach($candidate);
                }
            }
        }
        $this->setMatches($found);
        return $this;
    }

Usage Example

Exemple #1
0
 public function findInPlace($selector)
 {
     $query = new \QueryPath\CSS\DOMTraverser($this->matches);
     $query->find($selector);
     $this->setMatches($query->matches());
     return $this;
 }
All Usage Examples Of QueryPath\CSS\DOMTraverser::find