Symfony\Component\DomCrawler\Crawler::extract PHP Метод

extract() публичный Метод

You can extract attributes or/and the node value (_text). Example: $crawler->filter('h1 a')->extract(array('_text', 'href'));
public extract ( array $attributes ) : array
$attributes array An array of attributes
Результат array An array of extracted values
    public function extract($attributes)
    {
        $attributes = (array) $attributes;
        $count = count($attributes);
        $data = array();
        foreach ($this->nodes as $node) {
            $elements = array();
            foreach ($attributes as $attribute) {
                if ('_text' === $attribute) {
                    $elements[] = $node->nodeValue;
                } else {
                    $elements[] = $node->getAttribute($attribute);
                }
            }
            $data[] = $count > 1 ? $elements : $elements[0];
        }
        return $data;
    }

Usage Example

Пример #1
0
 public function extract($attribute, $asString = false)
 {
     return true === $asString ? implode(null, parent::extract($attribute)) : parent::extract($attribute);
 }
All Usage Examples Of Symfony\Component\DomCrawler\Crawler::extract