0

Here is the string.

$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...

alex
  • 479,566
  • 201
  • 878
  • 984
Prasad N
  • 543
  • 4
  • 10
  • 22

1 Answers1

0

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.

alex
  • 479,566
  • 201
  • 878
  • 984