3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $html = <<<EOF <table> <tr> <td>something</td> <td>1</td> <td>1</td> </tr> <tr> <td></td> <td>2</td> <td>2</td> </tr> <tr> <td></td> <td>3</td> <td>3</td> </tr> <tr> <td>anything</td> <td>4</td> <td>4</td> </tr> <tr> <td></td> <td>5</td> <td>5</td> </tr> <tr> <td> </td> <td>6</td> <td>6</td> </tr> <tr> <td>nothing</td> <td>7</td> <td>7</td> </tr> <tr> <td></td> <td>8</td> <td>8</td> </tr> <tr> <td>ontehing</td> <td>9</td> <td>9</td> </tr> <tr> <td></td> <td>10</td> <td>10</td> </tr> </table> EOF; $doc = new DOMDocument(); $doc->loadHTML($html); $xpath = new DOMXPath($doc); $query = ' //tr[td[1][contains(text(), "anything")]] | //tr[td[1][contains(text(), "anything")]] /following-sibling::tr[td[1][not(text())] and preceding-sibling::tr[1][td[1][not(text()) or contains(text(), "anything")]]] '; foreach ($xpath->query($query) as $res) { var_dump($doc->saveHTML($res)); }
Output for 5.3.6 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
string(71) "<tr> <td>anything</td> <td>4</td> <td>4</td> </tr> " string(63) "<tr> <td></td> <td>5</td> <td>5</td> </tr> "
Output for 5.0.0 - 5.1.1, 5.1.3 - 5.3.5
Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/B7KLr on line 74 NULL Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/B7KLr on line 74 NULL
Output for 5.1.2
Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/B7KLr on line 75 NULL Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /in/B7KLr on line 75 NULL
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/B7KLr on line 60
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/B7KLr on line 61
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/B7KLr on line 60