hi I have this html text. <select name=crap> <option value="0" selected="selected"></option> <!-- random comment --> <option value="1">some text</option> <select name=crap2> <option value="0" selected="selected"></option> <!-- random comment --> <option value="3">some text2</option> HTML: I need to get the value of the second option for both selectboxes. the values should be 1 and 3. so here is what've done till now with my regex pattern: $pat = '/<select[^>]*name\=\"[^\"]*\"[^>]*>[^<]*<option[^>]*>[^<]*<\/option>[^<]*<option[^>]*value\=\"([^\"]*)\"[^>]*>/s'; PHP: the problem is this pattern works only with the first option for both selectboxes I dont know how to ignore the <!-- random comment --> part.. I tried to put [^(<option)]* instead of [^<]* but no luck of makin this thing work.. any help would be appreciated..
Here you go, this should retrieve value 1 and value 3: <?php $html = <<<HTML <select name=crap> <option value="0" selected="selected"></option> <!-- random comment --> <option value="1">some text</option> <select name=crap2> <option value="0" selected="selected"></option> <!-- random comment --> <option value="3">some text2</option> HTML; if(preg_match_all('#<option value="([^\"]*)">#s', $html, $matches)) { //value 1 $firstvalue = $matches[1][0]; //value 3 $secondvalue = $matches[1][1]; } else { print("No matches found"); } ?> PHP:
thanks but this is not I'm lookin for.. I have more than 2 select boxes with lots of options.. what I need is to get the value of second option for each select box in the page..
the question is how can I ignore whole word using carrot ^. for example I want to use it like this: [^(<option)] I want to ignore the string in () but this is not workin.