Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    62
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Retrieve external div with PHP curl

    I'm using PHP curl to load an external page which works great, but I was wanting to load only one div section within it that contains these attributes on the external site.
    <div id="col-1-2-wrap" class="column" style="height: 1780px;">
    This is my code to load the external webpage.
    <?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.sportingpulse.com/club_info.cgi?c=0-2307-128783-0-0");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    $result = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://www.sportingpulse.com/$2$3', $result);
    echo $result;
    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,470
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    It looks like what you're trying to grab are all links to other pages.
    Is it those links you're looking to get? Or did you mean to get the results of the links?

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    62
    Thanks
    5
    Thanked 14 Times in 14 Posts
    Yes they're links for our basketball team fixtures and results in a div. We want to display them on our website, but without the headers and footers. It's a temporary fix until RSS feeds are implemented.

    I've managed to extract the div with is content, but not using curl.
    Here's the code for others to refer to.

    Only thing to remember is the css and images need aren't carried across this way. That why I was trying to get PHP curl working instead..... And divs with numbers in them can cause issues.
    <?php
    $filename = 'http://www.sportingpulse.com/club_info.cgi?c=0-2307-128783-0-0';
    $raw_file = file_get_contents($filename);
    $arr_remove = array("\r", "\n", "\t", "\s");
    $archivePage = str_replace($arr_remove, '', $raw_file);
    $content = preg_match('/<div[^>]*id="content-wrap">(.*?)<\\/div>/si',$archivePage,$matches);
    $matches[0] = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://www.sportingpulse.com/$2$3', $matches[0]);
    echo $matches[0];
    ?>

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    62
    Thanks
    5
    Thanked 14 Times in 14 Posts
    They're links for our basketball team fixtures in a div ideally displayed with formatting. We want to display them on our website, but without the headers and footers. It's a temporary fix until RSS feeds are implemented. This results of the hyperlinks don't need to be displayed until the user clicks on them.

    I've managed to extract the div with it's content, but not using curl.
    Here's the code for others to refer to.

    Only thing to remember is the css and images need aren't carried across this way. That's why I was trying to get PHP curl working..... And divs with numbers in them can cause issues.
    <?php
    $filename = 'http://www.sportingpulse.com/club_info.cgi?c=0-2307-128783-0-0';
    $raw_file = file_get_contents($filename);
    $arr_remove = array("\r", "\n", "\t", "\s");
    $archivePage = str_replace($arr_remove, '', $raw_file);
    $content = preg_match('/<div[^>]*id="content-wrap">(.*?)<\\/div>/si',$archivePage,$matches);
    $matches[0] = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#",'$1http://www.sportingpulse.com/$2$3', $matches[0]);
    echo $matches[0];
    ?>
    Last edited by waynenort; 08-12-2012 at 02:04 AM.

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,470
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    If you think there may be RSS (XML files) in the near future, you
    should wait for that. That will be the best method to get info.
    Maybe you can push them into getting it done, or offer some help?


  •  

    Posting Permissions

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