views:

76

answers:

3

I have a lot of option tags. I would like to remove the tags and get only the values. This is the code:

<?php
$result = preg_replace('/<option value=\"\d+\"  >([A-Za-z0-9]+)<\/option>/', '$1', $result);
?>

I cannot use strip_tags, strip_tags output:

id="pesq_marca" class="select164" size="1" onchange="exibeModelosSelectpesq_marca(this.value, 'C','','');" >SelecioneAUDIBMWCHEVROLETCITROENFIATFORDGMCHONDAHYUNDAIJEEPKIA MOTORSMERCEDES-BENZMITSUBISHINISSANPEUGEOTRENAULTSUZUKITOYOTAVOLKSWAGENADAMOAGRALEALFA ROMEOASIA MOTORSBRMBUGGYCADILLACCBTCHAMONIXCHANACHERYCHRYSLERDAEWOODAIHATSUDKWDODGEEFFAENGESAENVEMOFERRARIGURGELHAFEIHUMMERINFINITIIVECO-FIATJAGUARJINBEIJPXLADALAND ROVERLEXUSLIFAN MOTORSLINCOLNLOBINIMAHINDRAMASERATIMAZDAMERCURYMINIMIURAMPNEVIO BRENDLERPORSCHEPROTOTIPOPUMASATURNSEATSHELBYSIMCASMARTSSANGYONGSUBARUTROLLERVOLAREVOLVOWAYWILLYS

With this code, I get the content of $result and a lot of trash. What's wrong? Thank you.

+1  A: 

Exactly your question has been asked before - see this post, it will definitely help you (including sample code):

Stackoverflow: "php regex to read select form"

The regex in question (from that post) is preg_match_all( '@(<option value="([^"]+)">([^<]+)<\/option>)@', $options, $arr);

moontear
should be a comment
SilentGhost
Couldn't find any information on how to mark a post as duplicate or on how to link posts in the FAQ. Also I don't see how this is not an answer to the question. (Sorry for being totally off-topic, but thanks for pointing out that this should be a comment)
moontear
I cannot understand that. Thank you.
anoob
+1  A: 

Questions about HTML Parsing come up daily. Have a look at

See the linked duplicate for more details and search StackOverflow for DOM.

Gordon
+1  A: 
$result = preg_replace('/<option.*?>([A-Za-z0-9]+)<\/option>/', '$1', $result);
methodin
It doesn't work. I get the same trash as before... Thank you.
anoob
Can you post the trash?
methodin