Forum Moderators: coopster
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);
?>
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.
..
curl_setopt($curlh, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curlh);
//Do something with $result
echo $result;
$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.