0

From the following HTML code that does not have a specific structure but are just plain , how can I get the: (below you can find what I did using regex)

  1. 231435424
  2. 1800cc
  3. 163bhp
  4. Automatic
  5. Petrol
  6. Blue

Here is the HTML code

<td class="details">
    <a href="./view/3505089/"><span class="p_t">Audi A4</span></a>
    <a class="info" href="./view/3505089/">(Details)</a><br>
    <div class="attribs">
        Roadster
        <br>
        P.O: 35562, <span class="p_l">BURON</span>, Phone. 231435424<br>
        1800cc,
        163bhp,
        Automatic,
        Petrol,
        Blue,
    </div>
</td>

Here is what I was doing with regex

$bhps = array();
$gears = array();

preg_match_all('/(\d{2,3})bhp\b,/', $str2b, $bhps);
preg_match_all('#(A(.*?)tomatic|Ma(.*?)ual)#u', $str2b, $gears);

foreach .......
    $bhp = $bhps[1][$key];
    $gear = $gears[1][$key];
    ........
EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179
  • Are you trying to scrape a website's output? If not then if you can add some tags around your output then that would help to target spcific stuff – pal4life Oct 07 '13 at 19:43
  • If you the values are coming out in the same order each time you can do a split on comma and referrer to the position in the array that correlates to the value you are looking for – Seth McClaine Oct 07 '13 at 19:43
  • @pal4life unfortunately I can not add any tags because I scrape. – EnexoOnoma Oct 07 '13 at 19:46
  • @SethMcClaine I guess this is one possible solution. The values are coming out in the same order everytime. – EnexoOnoma Oct 07 '13 at 19:47
  • The classic [don't parse XML/HTML with RegExp](http://stackoverflow.com/q/701166/570812). Use DOM to find `div.attribs span.p_l` and extract info. – Passerby Oct 08 '13 at 03:08

0 Answers0