Symfony\Component\DomCrawler\Crawler::children PHP Method

children() public method

Returns the children nodes of the current selection.
public children ( ) : Crawler
return Crawler A Crawler instance with the children nodes
    public function children()
    {
        if (!$this->nodes) {
            throw new \InvalidArgumentException('The current node list is empty.');
        }
        $node = $this->getNode(0)->firstChild;
        return $this->createSubCrawler($node ? $this->sibling($node) : array());
    }

Usage Example

コード例 #1
0
 /**
  * Get the selected value from a select field.
  *
  * @param  \Symfony\Component\DomCrawler\Crawler  $select
  * @return array
  */
 protected function getSelectedValueFromSelect(Crawler $select)
 {
     $selected = [];
     foreach ($select->children() as $option) {
         if ($option->nodeName === 'optgroup') {
             foreach ($option->childNodes as $child) {
                 if ($child->hasAttribute('selected')) {
                     $selected[] = $this->getOptionValue($child);
                 }
             }
         } elseif ($option->hasAttribute('selected')) {
             $selected[] = $this->getOptionValue($option);
         }
     }
     return $selected;
 }
All Usage Examples Of Symfony\Component\DomCrawler\Crawler::children