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; function get_selected($html) { $doc = new DOMDocument; $doc->loadHTML($html); $xpath = new DOMXpath($regex); foreach ($xpath->query("//option") as $option) { $selected_value = $xpath->evaluate('string(@value)', $option); return $selected_value; } } var_dump( get_selected($html1) ); var_dump( get_selected($html2) ); var_dump( get_selected($html3) );
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $regex in /in/betQW on line 17 Fatal error: Uncaught TypeError: DOMXPath::__construct(): Argument #1 ($document) must be of type DOMDocument, null given in /in/betQW:17 Stack trace: #0 /in/betQW(17): DOMXPath->__construct(NULL) #1 /in/betQW(24): get_selected('<option selecte...') #2 {main} thrown in /in/betQW on line 17
Process exited with code 255.

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:
65.33 ms | 401 KiB | 8 Q