3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $html =<<<EOF <form> <select><option>foo</option><option>bar</option></select> <select><option>hello</option><option>PHP</option></select> </form> EOF; $dom = new DOMDocument; $dom->loadHTML($html); $dom->formatOutput = true; $xpath = new DOMXPath($dom); $selects = $xpath->query('//select'); foreach ($selects as $select) { $options = $xpath->query('//option', $select); foreach ($options as $option) $option->removeAttribute('selected'); $options->item(1)->setAttribute('selected','selected'); } echo $dom->saveHTML();
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><form> <select><option>foo</option> <option selected>bar</option></select><select><option>hello</option> <option>PHP</option></select> </form></body></html>
Output for 4.4.3 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/VQBjJ on line 15
Process exited with code 255.
Output for 4.4.2
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/VQBjJ on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/VQBjJ on line 15
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/VQBjJ on line 15
Process exited with code 255.