Retrieving content from a remote webpage using the CURL Functions in PHP

Category: Software and Systems Engineering
Author: Sean O'Donnell
Thu, Feb. 20th, 2003 @ 2:20:22 (MST)

This tutorial will explain how to rip content from other websites, and integrate their source code into your webpage, using the CURL Functions in PHP4

I have created this simple-to-use PHP Function, that handles the curl_init, curl_exec, and curl_close procedures, from 1 simple function execution.

Below is the source code...

* file: curl.php
* desc: example curl procedures
function curl_rip($str_url) {

/** initialize the CURL session */
$obj_curl curl_init($str_url);

/** execute the CURL session, return the results to the $list_results array */
$list_results curl_exec($obj_curl); 

/** close the CURL session */

/** return the contents of the output buffer (array) */
return $list_results[0];

/** execute the function, and print the results */
print curl_rip("");

This method is much easier than using the fopen/fread functions, but requires CURL to be installed on the server, and Support for it must be built into the PHP Configuration.

If your server does not have CURL support built in to the PHP Configuration, then you may resort to using the fopen functions.

Another issue, is that curl_exec and fread perform differently.

fread - returns the results

curl_exec - prints the results

So, for certain tasks, using fread is prefered.

Copyleft (<) 1998-2019