Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Question on CURL remote page inclusion

Including a portion of a web page

11:22 pm on May 1, 2008 (gmt 0)

New User

10+ Year Member

joined:May 25, 2005
votes: 0

Hi Folks,

My current web host only supports CURL for remote includes. For whatever reason, "fopen" really doesn't function properly. OK, no biggie, I replaced a former fopen script with a CURL script and it worked perfectly.

Only problem is that CURL includes the entire page. In my fopen script, I was able to specify which portions of the page I wanted included, by signifying a start point and end point in the script. I was wondering if anyone know how to do something similar in CURL.

I'll post the code below for all to see. Thanks in advance for any suggestions or hints:




9:33 am on May 2, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:July 12, 2007
votes: 0

What were you using with fopen to get parts of the page?
As fopen just opens a file and returns a handle, it doesnt actually do anything with that file.
2:40 pm on May 2, 2008 (gmt 0)

New User

10+ Year Member

joined:May 25, 2005
votes: 0

Thanks for the reply, Chimp. Please keep in mind I'm VERY novice to PHP and I really don't know all of the lingo.

Essentially, what the fopen script did was take a remote page and display it on my site either in whole or part. If I wanted to display a part of a page, there was a space where I could enter the portion of HTML code before the part I wanted to include and then another to signify the endpoint of the page I wanted to include. I'll post it here:

<script language="php">

$file = fopen("http://www.mysite.com", "r");
$rf = fread($file, 20000);
$grab = eregi("HTML OF WHERE TO START(.*)HTML OF WHERE TO END", $rf, $printing);
$printing[1] = str_replace("#cccc99", "white", $printing[1]);
echo $printing[1];

Basically, I'd like to accomplish the same things with CURL. I'd like to be able to insert a snippet of HTML code that tells the script where to start including the page and then where to end. Right now, I can just include the whole page.

Does this make it any clearer? In the end, I just would like to be able to include a portion of a web page, not the whole page.

3:00 am on May 3, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 13, 2008
votes: 0

I suggest you pass some parameters to 'http://www.myurl.com/' (assuming you own this page) and depending on the passed parameter display what's needed. OR you can have curl_exec return a string as a result which you can manipulate then display:

curl_setopt($curlh, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curlh);
//Do something with $result
echo $result;

12:41 pm on May 3, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 3, 2007
votes: 0

$hc = new eHttpClient();
$html = $hc->get("http://www.mysite.com/");
//I don't like ereg ... I use preg
if(!preg_match("@HTML OF WHERE TO START(.*)HTML OF WHERE TO END@is",$html,$printing)) die("ERROR MATCHING REGEXP");
$printing[1] = str_replace("#cccc99", "white", $printing[1]);
echo $printing[1];

This is it Dan. If you need further help lemme know but if you don't get this code than ... gotta study some more PHP.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members