1

I would like to use preg_match in PHP to parse out the content of the div with the id "codigoImagem" from the following html section:

<tbody>
 <tr valign="bottom">
  <td>
   <img src="../../imagens/boleto/logo_boleto.gif" width="236" height="30" alt="Bradesco |237-2|">
   <span class="codigo">
    <div id="codigoImagem">2379285923  59799.436395  57000.723007  1  57160000036698</div>
   </span>
  </td>
 </tr>
</tbody>
hopper
  • 4,230
  • 8
  • 36
  • 49
  • The answer is: you *don't* want to use `preg_match` for that. See the linked question marked as a possible duplicate above. – Dan Fego May 31 '13 at 19:16

2 Answers2

2

The good way is to use the DOMDocument for that:

$doc = new DOMDocument();
@$doc->loadHTML($html);
$result = $doc->getElementById("codigoImagem")->nodeValue;
var_dump($result);
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
1
if (preg_match("/id=\"codigoImagem\">([^<]+)/", $html, $m)) print $m[1];
mpapec
  • 50,217
  • 8
  • 67
  • 127
  • I get this array $m : http://puu.sh/35knA.png . I want to get the entire code within that div. – hopper May 31 '13 at 19:23