3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * @link http://stackoverflow.com/questions/10543397/php-domnode-nodevalue-doesnt-work-properly */ $html = <<<HTML <option value="A26JUYT14N57PY">Aleksander&#39;s Kindle Cloud Reader</option> <option value="A13400OMTGFDRH">Aleksander&#39;s Kindle for PC</option> <optgroup label="----OR----" style="color:#999;font-style:normal;font-weight:normal"> </optgroup> <option value="add-new">Register a new Kindle</option> HTML; $dom = new DOMDocument(); $dom->loadHTML($html); $options = $dom->getElementsByTagName('option'); foreach($options as $option) { $attr = $option->getAttribute('value'); $value = $option->nodeValue; printf("%s : %s\n", $attr, $value); }
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
A26JUYT14N57PY : Aleksander's Kindle Cloud Reader A13400OMTGFDRH : Aleksander's Kindle for PC add-new : Register a new Kindle
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/N6D7W on line 13
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/N6D7W on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/N6D7W on line 13