3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html1 = <<<EOT <option selected="selected" value="1">value text</option> EOT; $html2 = <<<EOT <option selected value="1">value text</option> EOT; $html3 = <<<EOT <option value="the devil with **selected** ">value text</option> EOT; $html4 = <<<EOT <option selected="selected" value="1">value text</option> <option value="the devil with **selected** ">value text</option> <option selected value="1">value text</option> EOT; function get_selected($html) { $results = array(); $doc = new DOMDocument; $doc->loadHTML($html); $xpath = new DOMXpath($doc); foreach ($xpath->query("//option") as $option) { $selected_value = $xpath->evaluate('string(@selected)', $option); $results[] = $selected_value; } return $results; } var_dump( '1', get_selected($html1) ); var_dump( '2, gget_selected($html2) ); var_dump( '3', gget_selected($html3) ); var_dump( '4', gget_selected($html4) );
Output for 7.0.0 - 7.0.1
Parse error: syntax error, unexpected '3' (T_LNUMBER), expecting ',' or ')' in /in/Nibai on line 33
Process exited with code 255.
Output for 5.5.24 - 5.5.30, 5.6.8 - 5.6.16
Parse error: syntax error, unexpected '3' (T_LNUMBER) in /in/Nibai on line 33
Process exited with code 255.

preferences:
160.51 ms | 1395 KiB | 25 Q