Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Forked from brunomoraes/gist:577cf1dff8454f074a634f4bf9d1f0e2
Last active July 4, 2018 20:33
Show Gist options
  • Save wilcorrea/0427dc9bb09eb24c4722b4e2dea4b174 to your computer and use it in GitHub Desktop.
Save wilcorrea/0427dc9bb09eb24c4722b4e2dea4b174 to your computer and use it in GitHub Desktop.
<?php
try {
$tr_elements = $crawler2->filterXPath('//table/tr');
$result = $crawler2->filter('#ctl00_ContentPlaceHolder1_dlResultados')->html();
$crawler3 = new Crawler($result);
$headerData = [];
$counter = 0;
$node = $crawler3->filter('.resultadocdital')->each(function (Crawler $node, $i) use (&$headerData, &$counter) {
$PATTERN = '/\<strong\>(?<name>[^\<^\>]*)\s?:\s?<\/strong\>(?<content>[^\<^\>]*)/m';
preg_match_all($PATTERN, trim($node->html()), $matches, PREG_SET_ORDER, 0);
if (!isset($matches[0])) {
return [];
}
$headerData[$counter] = [];
$counter++;
foreach ([0, 1, 2, 3, 4, 5, 6, 7, 8] as $key) {
if (!isset($matches[$key])) {
continue;
}
$match = $matches[$key];
$headerData[$counter][] = [
'name' => $this->clear($match['name']),
'content' => $this->clear($match['content']),
];
}
});
// use $headerData in template;
} catch (InvalidArgumentException $e) {
return "error";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment