Description
Returns the text of a URL as a string. Call using getUrlText($url), this can replace file_get_contents().
Run
| View code [+] |
Create a snippet based on this »
View in new window »
<?php
function getUrlText($url)
{
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_PORT, 80); //Set the port number
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$document = curl_exec($ch);
return $document;
}
?>
Comments (1) | View comments for all versions (1)
jeff (author) said: 16 May
This has been deprecated in favor of curl_function
Log in if you have a Kogbox account.