-2

Possible Duplicate:
How to parse and process HTML with PHP?

I have the code for a number of HTML selectboxes stored in a database, e. g.:

<select id="appearance_body_style" class="cls_selectbox"> 
 <option value="">-- select --</option> 
 <option value="underweight">untergewichtig</option>
 <option value="slim">schlank</option>
 <option value="athletic">athletisch</option>
 <option value="average">durchschnittlich</option> 
 <option value="full_figured">mollig</option> 
 <option value="overweight">übergewichtig</option> 
</select>

I need two regular expressions:

  • one to get the string from the value attribute.
  • one to get the string between the options tags.

Everything needs to be in a loop to extract those two strings line for line.

Community
  • 1
  • 1
Andreas
  • 545
  • 2
  • 11
  • 24
  • 2
    We have hundreds of questions asking how to parse X from HTML question already. Please do research and show us you put some effort trying to solve this on your own before asking. We are not code monkeys. – Gordon Jan 16 '12 at 09:58
  • you can use https://gist.github.com/1358174 and for a) `//option/@value` and for b) `//option` – Gordon Jan 16 '12 at 10:00

2 Answers2

2

Try this:

$match = array();
preg_match_all( '~<option value="([^"]+)">([^<>]+)</option>~', $html, $match, PREG_SET_ORDER);
print_r( $match);

See also php documentation for preg_match_all

Vyktor
  • 20,559
  • 6
  • 64
  • 96
0

I think you would have more luck with something like this: http://simplehtmldom.sourceforge.net/

jon
  • 5,986
  • 5
  • 28
  • 35