Wednesday 9 March 2016

How to fetch web text using cURL.

How to fetch web text using cURL.

 
Hello Friends today i will teach you , how to fetch web text using cURL. The full form of cURL is CLIENT URL LIBRARY. It is a function of PHP there are many sub function available like curl_close(close a cURL session) , curl_errno(Return the last error number) , curl_file_create(create the cURL file object) etc. so many function are available but today i teach you curl_setopt.
It is use to Set an option for a cURL transfer. The small demo are following. you can use in notepad or any text editer.

Step are following.

1) Open notepad.
2) Save file in xampp/hddoc in create your folder and name your wish. And file name i am saving curl.php you can different name choose. Write a code bellow i your php file. I will Show you output in image and source code image.



<strong>Hello Friend</strong>

<?php

$chandle = curl_init();
$url="www.top-tricksandtips.blogspot.in";
curl_setopt($chandle,CURLOPT_URL,$url);
curl_setopt($chandle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($chandle,CURLOPT_CONNECTTIMEOUT,5);
$curlResult=curl_exec($chandle);
curl_close($chandle);

echo $curlResult;

?>



3) In this file i am write www.top-tricksandtips.blogspot.in you can write your choice url.
4) Run in browser localhost/foldername/filename.php and press enter and show the magic.. and enjoy.

Thank you.

1 comment: