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 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in /in/bv7I2 on line 60 Array ( [0] => [1] => K0074 [2] => B2004 )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.28
Array ( [0] => [1] => K0074 [2] => B2004 )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [0] => [1] => K0074 [2] => B2004 )

preferences:
181.58 ms | 411 KiB | 5 Q