-2

Possible Duplicate:
How to parse and process HTML with PHP?

I have HTML document which contains many records with following format:

<tr><td>af</td><td>Afrikaans</td></tr>

Please, tell me, how can I extract "af" and "Afrikaans" using regular expression? Thank you.

Community
  • 1
  • 1
user1445877
  • 83
  • 1
  • 1
  • 8

2 Answers2

1

This is just a simple example to get you started, but depending on the structure of the HTML you will need to make some tweaks:

$s = <<<EOM
<tr><td>af</td><td>Afrikaans</td></tr>
EOM;

$d = new DOMDocument;
$d->loadHTML($s);
foreach ($d->getElementsByTagName('td') as $node) {
    echo $node->nodeValue;
}

See also, the DOMDocument documentation

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
0

You should use DOM, SAX, SimpleXML, PHPQuesry, tidy instead of Regular expressions for parsing XML

odiszapc
  • 4,089
  • 2
  • 27
  • 42