3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /* Just compose the HTML sample */ $html='<html><head></head><body>'; $html.='<table class="grilla"><tbody><tr class="textEncabezadoGrilla" bgcolor="#C0DAF1" align="center"> <th>Juzgado Policía Local</th> <th>Rol Causa</th> </tr> <tr> <td class="textgrid2">2 JPL PROVIDENCIA</td> <td class="textgrid2">018092 - 2010</td> </tr> <tr> <td class="textgrid1">OVALLE JPL</td> <td class="textgrid1">13115 - 2010</td> </tr> </tbody></table> <table class="grilla"><tbody><tr class="textEncabezadoGrilla" bgcolor="#C0DAF1" align="center"> <th>Juzgado Policía Local</th> <th>Rol Causa</th> </tr> <tr> <td class="textgrid2">2 JPL PROVIDENCIA</td> <td class="textgrid2">018092 - 2010</td> </tr> <tr> <td class="textgrid1">OVALLE JPL</td> <td class="textgrid1">13116 - 2011</td> </tr> </tbody></table>'; $html.="</body></html>"; $doc=new DOMDocument(); $doc->loadHTML($html); $xpath=new DOMXPath($doc); $tds = array(); var_dump($xpath->query('//table[@class="grilla"]/tbody/tr/td/text()')); foreach($xpath->query('//table[@class="grilla"]') as $key => $td) { array_push($tds, $td); } print_r($tds); $ee = array_chunk($tds, 2);
based on 1hrJu
Output for 7.0.20, 7.1.5 - 7.2.0
object(DOMNodeList)#11 (1) { ["length"]=> int(8) } Array ( [0] => DOMElement Object ( [tagName] => table [schemaTypeInfo] => [nodeName] => table [nodeValue] => Juzgado Policía Local Rol Causa 2 JPL PROVIDENCIA 018092 - 2010 OVALLE JPL 13115 - 2010 [nodeType] => 1 [parentNode] => (object value omitted) [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => [nextSibling] => (object value omitted) [attributes] => (object value omitted) [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => table [baseURI] => [textContent] => Juzgado Policía Local Rol Causa 2 JPL PROVIDENCIA 018092 - 2010 OVALLE JPL 13115 - 2010 ) [1] => DOMElement Object ( [tagName] => table [schemaTypeInfo] => [nodeName] => table [nodeValue] => Juzgado Policía Local Rol Causa 2 JPL PROVIDENCIA 018092 - 2010 OVALLE JPL 13116 - 2011 [nodeType] => 1 [parentNode] => (object value omitted) [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => (object value omitted) [nextSibling] => [attributes] => (object value omitted) [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => table [baseURI] => [textContent] => Juzgado Policía Local Rol Causa 2 JPL PROVIDENCIA 018092 - 2010 OVALLE JPL 13116 - 2011 ) )
Output for 5.3.20 - 7.0.6, 7.1.0
object(DOMNodeList)#11 (1) { ["length"]=> int(8) } Array ( [0] => DOMElement Object ( [tagName] => table [schemaTypeInfo] => [nodeName] => table [nodeValue] => Juzgado Policía Local Rol Causa 2 JPL PROVIDENCIA 018092 - 2010 OVALLE JPL 13115 - 2010 [nodeType] => 1 [parentNode] => (object value omitted) [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => [nextSibling] => (object value omitted) [attributes] => (object value omitted) [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => table [baseURI] => [textContent] => Juzgado Policía Local Rol Causa 2 JPL PROVIDENCIA 018092 - 2010 OVALLE JPL 13115 - 2010 ) [1] => DOMElement Object ( [tagName] => table [schemaTypeInfo] => [nodeName] => table [nodeValue] => Juzgado Policía Local Rol Causa 2 JPL PROVIDENCIA 018092 - 2010 OVALLE JPL 13116 - 2011 [nodeType] => 1 [parentNode] => (object value omitted) [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => (object value omitted) [attributes] => (object value omitted) [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => table [baseURI] => [textContent] => Juzgado Policía Local Rol Causa 2 JPL PROVIDENCIA 018092 - 2010 OVALLE JPL 13116 - 2011 ) )