Skip to content

Instantly share code, notes, and snippets.

@kaja47
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaja47/c88bd5cb1b8bea1994b1 to your computer and use it in GitHub Desktop.
Save kaja47/c88bd5cb1b8bea1994b1 to your computer and use it in GitHub Desktop.
Matcher examples
<?php
$m = Matcher::multi('//table[@id="egmFixtureList"]/tr[@class]', [
'datum' => 'td[@colspan]',
'spielnr' => 'td[1]',
'anpfiff' => 'td[2]',
'team1' => 'td[3]/a/text()',
'team2' => 'td[5]/a/text()',
'spielbericht' => 'td[7]/a/@href',
])->fromHtml()->map(function ($rows) {
$datum = null;
foreach ($rows as $i => & $row) {
if ($row['datum']) {
$datum = $row['datum'];
unset($rows[$i]);
} else {
$row['datum'] = $datum;
}
}
return $rows;
});
<?php
$m = Matcher::multi('//table[@id="egmFixtureList"]/tr[@class and not(td[@colspan])]', [
'datum' => 'preceding-sibling::tr[td[@colspan]][1]',
'spielnr' => 'td[1]',
'anpfiff' => 'td[2]',
'team1' => 'td[3]/a/text()',
'team2' => 'td[5]/a/text()',
'spielbericht' => 'td[7]/a/@href',
])->fromHtml();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment