Replace file_get_contents/fopen with cURL for Fetch

Some web hosts disable file_get_contents function. Most of them have curl library installed. This post help you to replace function for file_get_contents, using CURL library.

PHP Code
function to get url and return content available on the page.

<?php function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } ?>

Using this function is easy, just like file_get_contents function :

<?php
echo file_get_contents_curl('http://www.smartwebcare.com/');
?>

 

Published by

Smart Web Care

Smart Web Care offers a wide range of IT Solutions ranging from Website Development, E-Commerce Solutions, Multimedia, Brand Promotions, Graphic design, Domain Registration, Android/iOS App developer,Web Designer, Software Application Company, Web hosting company, IT support and services, Internet Marketing Service, Marketing Consultant Servers, Web Hosting and Tanning provider.