This is a discussion on DOMDocument or HTML parser? within the PHP Language forums, part of the PHP Programming Forums category; I want to extract the first <p> from a HTML, e.g. ================================== <?php $html = <<<...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I want to extract the first <p> from a HTML, e.g.
================================== <?php $html = <<<EOT <div> <p> paragraph1 </p> <p> paragraph2 </p> <div id="test"></div> </div> EOT; $doc = new DOMDocument(); $doc->loadHTML($html); $lists = $doc->getElementsByTagName("*"); print_r($lists); ?> ================================== Is it possible to do this using DOMDocument or other HTML parser recommended? Thanks. |
|
|||
|
howa wrote:
> I want to extract the first <p> from a HTML, e.g. > Is it possible to do this using DOMDocument or other HTML parser > recommended? $doc = new DOMDocument(); $doc->loadHTML($html); $firstParagraph = $doc->getElementsByTagName("p")->item(0); -- Toby A Inkster BSc (Hons) ARCS [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux] [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 27 days, 17:30.] Bottled Water http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/ |
![]() |
| Thread Tools | |
| Display Modes | |
|
|