anoob
anoob

Reputation: 9

preg_replace: remove tags

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.

Upvotes: 0

Views: 4590

Answers (3)

mike.k
mike.k

Reputation: 3457

Try this:

preg_match_all('/<option [^>]*?>(.*)<\/option>/', $text, $match);
print_r($match[1]);

Upvotes: 0

methodin
methodin

Reputation: 6710

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

Upvotes: 1

Dennis G
Dennis G

Reputation: 21798

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);

Upvotes: 1

Related Questions