3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<'TAG' <html> <body> <table class="searchTable" cellspacing="0" cellpadding="5" style="width: 100%;"> <tbody> <tr> <th>Book</th> <th>Model Name</th> <th>Description</th> <th>Category</th> </tr> <tr> <td> <a onclick="getFullData( '', 'K0074', 'B2004' );" href="">K0072</a> </td> <td>B2004</td> <td>K0074 Description</td> <td>K0074 Category</td> </tr> </tbody> </table> </body> </html> TAG; $doc = new DOMDocument(); $doc->loadHTML($html); $tables = $doc->getElementsByTagName('table'); foreach ($tables as $table) { if ($table->getAttribute('class') !== 'searchTable') { continue; } $rows = $table->getElementsByTagName('tr'); foreach ($rows as $row) { $cells = $row->getElementsByTagName('td'); // Sanity check that we have four rows or skip it if (4 !== count($cells)) { continue; } // Sanity check that the first cell has a link inside it $firstCellLinks = $cells[0]->getElementsByTagName('a'); if (1 !== count($firstCellLinks)) { continue; } // Make sure the first link has an onclick attribute if (!$firstCellLinks[0]->hasAttribute('onclick')) { continue; } // Finally, get the contents of the cell. This can be simplified to a one-line but // I've expanded it to be more obvious. $firstCellLinkOnClick = $firstCellLinks[0]->attributes['onclick']->value; $firstCellLinkOnClickParamsAsString = preg_replace('/getFullData\(([^)]+)\);/', '$1', $firstCellLinkOnClick); $firstCellLinkOnClickParamsAsArray = str_getcsv($firstCellLinkOnClickParamsAsString, ',', "'"); print_r($firstCellLinkOnClickParamsAsArray); /* Array ( [0] => [1] => K0074 [2] => B2004 ) */ } }
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => [1] => K0074 [2] => B2004 )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
165.91 ms | 405 KiB | 5 Q