preg_match_all for <option></option> to get all matching values
Here is the string.
开发者_StackOverflow$string = <option class="abcd" value="1.5">Some Text with White Spaces</option>
I want to get all matching variables (1.5
& Some Text with White Spaces
) using preg_match_all or something similar. I was doing this a long ago but I don't remember it now. Hope you can help...
I couldn't answer a html & regex question on Stack Overflow without mentioning please use a parser.
However, if you were really keen on a regex, you could see below.
If your strings look like that, then you could use...
preg_match_all('/<option\sclass="[^"]*"\svalue="([^"]*)">([^>]*)<\/option>/', $string, $matches);
var_dump($matches);
$matches[1]
will have the value
attribute and $matches[2]
will have the text node.
精彩评论