Hi I have an issue with the regular expression based off the question below:
Question: [php-regex-to-read-select-form][1]
The HTML code I wish for the regular expression to go through
<select name="List">
<option selected="selected" value="HAR">HAR</option>
<option value="HAY">HAY</option>
<option value="ZZZ">ZZZ</option>
</select>
The php I currently have is as follows:
preg_match_all( '@(<option value="([^"]+)">([^<]+)<\/option>)@', $html, $viewstate);
echo "<pre>";
print_r($viewstate);
echo "</pre>";
die();
The output from that is as follows:
Array
(
[0] => Array
(
[0] => HAY
[1] => ZZZ
)
[1] => Array
(
[0] => HAY
[1] => ZZZ
)
[2] => Array
(
[0] => HAY
[1] => ZZZ
)
[3] => Array
(
[0] => HAY
[1] => ZZZ
)
)
So I am a bit confused why it creates the results muiltiple times and do now know how to get it to get the <option
tag with the selected attribute set.