SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cURL - Returning only a certain portion of HTML

    I have been using SimpleXML, and got used to calling the document tree like this:
    Code:
    $xml->params->param->id;
    Now, however, I am trying to return a whole page, but only need to know the contents of one div. Can cURL do anything clever like SimpleXML, or am I going to have to get my hands dirty using a find and replace?

    However, how would a find and replace work? I want to say, hey, find the div with an id of totalnumber. Then, just return the contents of this div to me, store it, and get rid of everything else. Thanks.

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Have you given any thought to XPath?

    PHP Code:
    <?php
    $sHTML 
    '
    <html>
        <head></head>
        <body>
            <div id="foo">
                I am foo
            </div>
            <div id="bar">
                I be bar
            </div>
        </body>
    </html>
    '
    ;

    $oXPath = new DOMXPath(DOMDocument::loadHTML($sHTML));

    echo 
    $oXPath->query("//div[@id='foo']")->item(0)->nodeValue#I am foo
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Er, no, I didn't even knew it existed!
    So, back to reading the docs for me then!

    Thanks very much.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    No problem Adam, good luck!
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •