DOMDocument or HTML parser?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I want to extract the first <p> from a HTML, e.g.


$html = <<<EOT

    <p> paragraph1 </p>

    <p> paragraph2 </p>

    <div id="test"></div>



$doc = new DOMDocument();

$lists = $doc->getElementsByTagName("*");




Is it possible to do this using DOMDocument or other HTML parser


Re: DOMDocument or HTML parser?

howa wrote:
Quoted text here. Click to load it

$doc = new DOMDocument();
$firstParagraph = $doc->getElementsByTagName("p")->item(0);

Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux, up 27 days, 17:30.]

                               Bottled Water

Site Timeline