Speed up development with full-stack environments for every branch.

Learn More

Curl module example - Fetching url and displaying the content

Forked from Hello World.

483 Runs 947 Views 512 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php
/**
 * Curl example - Fetching an url and displaying the content found on that url 
 */
//initializes a new session and return a cURL handle for use with the curl_setopt(), curl_exec(), and curl_close() functions.
$ch = curl_init();

// set the url to fetch 
curl_setopt($ch, CURLOPT_URL, "example.com");

//return the transfer (the result of curl_exec()) as a string instead of outputing directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string 
$output = curl_exec($ch);

// close curl resource to free up system resources 
curl_close($ch);

//display the content found on example.com
echo "<br /><center><b><u>BELOW this line is the content fetched from www.example.com:</u></b></center><br />";
echo $output;
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).