public function Crawler::extract in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/dom-crawler/Crawler.php \Symfony\Component\DomCrawler\Crawler::extract()
Extracts information from the list of nodes.
You can extract attributes or/and the node value (_text).
Example:
$crawler->filter('h1 a')->extract(array('_text', 'href'));
Parameters
array $attributes An array of attributes:
Return value
array An array of extracted values
File
- vendor/
symfony/ dom-crawler/ Crawler.php, line 594
Class
- Crawler
- Crawler eases navigation of a list of \DOMElement objects.
Namespace
Symfony\Component\DomCrawlerCode
public function extract($attributes) {
$attributes = (array) $attributes;
$count = count($attributes);
$data = array();
foreach ($this 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;
}