Welcome to WebmasterWorld Guest from 54.226.183.49

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Question on CURL remote page inclusion

Including a portion of a web page

     

TurboDan

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

10+ Year Member



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:

<?php

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://www.myurl.com/');
curl_exec($curl_handle);
curl_close($curl_handle);

?>

PHP_Chimp

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

WebmasterWorld Senior Member 5+ Year Member



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.

TurboDan

2:40 pm on May 2, 2008 (gmt 0)

10+ Year Member



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]);
fclose($file);
echo $printing[1];
</script>

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.

ag_47

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

5+ Year Member



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;

5ubliminal

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

5+ Year Member




$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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month