How to call url from php using C-url :: alternative to file_get_contents()

This is a nice and simple substitute to get_file_contents() using curl, it returns FALSE if $contents is empty.

<?php
function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);

if ($contents) return $contents;
else return
FALSE;
}
?>

Then another question

How to enable cURL in your server ?

To enable curl library we need to modify the php.ini file.

1) Locate the following files:
apache\bin\php.ini
php\php.ini
php\php4\php.ini or php\php5\php.ini

2) Uncomment the following line on your php.ini file by removing the semicolon.

;extension=php_curl.dll

3) Restart your apache server.

4) Check your phpinfo if curl was properly enabled.

Otherwise you can dynamically enable the library by calling dl(); function. But it is deprecated by new version of PHP

About

me : yeay its me arun

Tagged with: , , , , , , , , , ,
Posted in PHP, Programming
4 Comments » for How to call url from php using C-url :: alternative to file_get_contents()
  1. cwxwwwxdfvwwxwx says:

    well, hi admin adn people nice forum indeed. how’s life? hope it’s introduce branch ;)

  2. jody says:

    Thanks! :) it helped very much

  3. Abhraham says:

    helo admin,
    Thank you for the post.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>