Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-11-2012, 02:34 AM   PM User | #1
waynenort
New Coder

 
Join Date: Jul 2012
Posts: 62
Thanks: 5
Thanked 14 Times in 14 Posts
waynenort is an unknown quantity at this point
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.
Quote:
<div id="col-1-2-wrap" class="column" style="height: 1780px;">
This is my code to load the external webpage.
Quote:
<?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;
?>
waynenort is offline   Reply With Quote
Old 08-12-2012, 12:46 AM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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?
mlseim is offline   Reply With Quote
Old 08-12-2012, 01:45 AM   PM User | #3
waynenort
New Coder

 
Join Date: Jul 2012
Posts: 62
Thanks: 5
Thanked 14 Times in 14 Posts
waynenort is an unknown quantity at this point
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.
Quote:
<?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];
?>
waynenort is offline   Reply With Quote
Old 08-12-2012, 02:01 AM   PM User | #4
waynenort
New Coder

 
Join Date: Jul 2012
Posts: 62
Thanks: 5
Thanked 14 Times in 14 Posts
waynenort is an unknown quantity at this point
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.
Quote:
<?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..
waynenort is offline   Reply With Quote
Old 08-12-2012, 02:24 AM   PM User | #5
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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?
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:59 PM.


Advertisement
Log in to turn off these ads.