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"]/tbody/tr/td/text()') as $key => $td) { array_push($tds, $td); } print_r($tds); $ee = array_chunk($tds, 2);
based on 3ONcI
Output for 7.0.20, 7.1.5 - 7.2.0
object(DOMNodeList)#11 (1) { ["length"]=> int(8) } Array ( [0] => DOMText Object ( [wholeText] => 2 JPL PROVIDENCIA [data] => 2 JPL PROVIDENCIA [length] => 17 [nodeName] => #text [nodeValue] => 2 JPL PROVIDENCIA [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [nextSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 2 JPL PROVIDENCIA ) [1] => DOMText Object ( [wholeText] => 018092 - 2010 [data] => 018092 - 2010 [length] => 13 [nodeName] => #text [nodeValue] => 018092 - 2010 [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [nextSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 018092 - 2010 ) [2] => DOMText Object ( [wholeText] => OVALLE JPL [data] => OVALLE JPL [length] => 10 [nodeName] => #text [nodeValue] => OVALLE JPL [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [nextSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => OVALLE JPL ) [3] => DOMText Object ( [wholeText] => 13115 - 2010 [data] => 13115 - 2010 [length] => 12 [nodeName] => #text [nodeValue] => 13115 - 2010 [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [nextSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 13115 - 2010 ) [4] => DOMText Object ( [wholeText] => 2 JPL PROVIDENCIA [data] => 2 JPL PROVIDENCIA [length] => 17 [nodeName] => #text [nodeValue] => 2 JPL PROVIDENCIA [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [nextSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 2 JPL PROVIDENCIA ) [5] => DOMText Object ( [wholeText] => 018092 - 2010 [data] => 018092 - 2010 [length] => 13 [nodeName] => #text [nodeValue] => 018092 - 2010 [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [nextSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 018092 - 2010 ) [6] => DOMText Object ( [wholeText] => OVALLE JPL [data] => OVALLE JPL [length] => 10 [nodeName] => #text [nodeValue] => OVALLE JPL [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [nextSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => OVALLE JPL ) [7] => DOMText Object ( [wholeText] => 13116 - 2011 [data] => 13116 - 2011 [length] => 12 [nodeName] => #text [nodeValue] => 13116 - 2011 [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [nextSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 13116 - 2011 ) )
Output for 5.3.20 - 7.0.6, 7.1.0
object(DOMNodeList)#11 (1) { ["length"]=> int(8) } Array ( [0] => DOMText Object ( [wholeText] => 2 JPL PROVIDENCIA [data] => 2 JPL PROVIDENCIA [length] => 17 [nodeName] => #text [nodeValue] => 2 JPL PROVIDENCIA [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 2 JPL PROVIDENCIA ) [1] => DOMText Object ( [wholeText] => 018092 - 2010 [data] => 018092 - 2010 [length] => 13 [nodeName] => #text [nodeValue] => 018092 - 2010 [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 018092 - 2010 ) [2] => DOMText Object ( [wholeText] => OVALLE JPL [data] => OVALLE JPL [length] => 10 [nodeName] => #text [nodeValue] => OVALLE JPL [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => OVALLE JPL ) [3] => DOMText Object ( [wholeText] => 13115 - 2010 [data] => 13115 - 2010 [length] => 12 [nodeName] => #text [nodeValue] => 13115 - 2010 [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 13115 - 2010 ) [4] => DOMText Object ( [wholeText] => 2 JPL PROVIDENCIA [data] => 2 JPL PROVIDENCIA [length] => 17 [nodeName] => #text [nodeValue] => 2 JPL PROVIDENCIA [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 2 JPL PROVIDENCIA ) [5] => DOMText Object ( [wholeText] => 018092 - 2010 [data] => 018092 - 2010 [length] => 13 [nodeName] => #text [nodeValue] => 018092 - 2010 [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 018092 - 2010 ) [6] => DOMText Object ( [wholeText] => OVALLE JPL [data] => OVALLE JPL [length] => 10 [nodeName] => #text [nodeValue] => OVALLE JPL [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => OVALLE JPL ) [7] => DOMText Object ( [wholeText] => 13116 - 2011 [data] => 13116 - 2011 [length] => 12 [nodeName] => #text [nodeValue] => 13116 - 2011 [nodeType] => 3 [parentNode] => (object value omitted) [childNodes] => [firstChild] => [lastChild] => [previousSibling] => [attributes] => [ownerDocument] => (object value omitted) [namespaceURI] => [prefix] => [localName] => [baseURI] => [textContent] => 13116 - 2011 ) )