tags:

views:

35

answers:

2

i need to replace combobox like this. eg:-

<select sistem="" name="answer5" >
<option>math</option>

<option>science</option>

<option selected="selected">engineering</option>

<option>English</option></select>

result shuld be(AFTER REPLACED) :- {answer5}

i have tried this but failed:

preg_replace('|<SELECT(.*)name="'.$name.'"(.*)>(.*)</SELECT>|U', '{'.$name.'}',$string);
+1  A: 

Please have a look at the many many questions on SO regarding regular expressions and html.

spoiler: html is not something you can parse with regular expression, since html is not a regular language, use xpath instead:

$result = $xpath->query('//select/@name');
for ($i = 0; $i < $result->length; $i++) {
    echo "{" . $result->item($i)->wholeText . "}";
}
soulmerge
actualy i have the name as varibel
Kombuwa
only i need is replace it
Kombuwa
Then you need to change the DOM tree. Have a look at the DOMNode docs, you'll need to replace child nodes: http://us2.php.net/manual/en/class.domnode.php
soulmerge
A: 

using this code ihave removed all option tags;

$string= preg_replace( "/<option[^>]*>[^<]*/i", '', $string );

now i have to remove is

<select sistem="" name="answer5" lesson="">
</select>
Kombuwa