Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,560 members, 7,823,470 topics. Date: Friday, 10 May 2024 at 10:31 AM

Download A Url’s Content Using PHP Curl - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Download A Url’s Content Using PHP Curl (965 Views)

Help! Webscraping With PHP Curl Is Not Working / Who Knows How To Login Nairaland With Php/curl / Problems Using Php Curl (2) (3) (4)

(1) (Reply)

Download A Url’s Content Using PHP Curl by skptricks: 8:31am On Dec 25, 2017
----------------------------------------------------------------------------------------------------
Link : http://www.skptricks.com/2017/12/download-urls-content-using-php-curl.html
----------------------------------------------------------------------------------------------------

In this tutorial we are going to learn how to extract or download the content from the specific URL. Nowadays it is a common and useful technique to extract data from another server. By this way we can extract useful data like meta tag details, html attribute/ tags details.
PHP's cURL library, which often comes with default shared hosting configurations, allows web developers to complete this task.


Lets see the below function which will extract information from specific URL.
PHP cURL Method.

/* gets the data from a URL */
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

To call get_data() function, you need to mention below statement in PHP tag.
$returned_content = get_data('https://www.skptricks.com');

Alternative Method

Alternatively, you can use the file_get_contents function remotely, but many hosts don't allow this.

<?php
$URL ="http://www.skptricks.com"
file_get_contents($URL)
?>


----------------------------------------------------------------------------------------------------
Link : http://www.skptricks.com/2017/12/download-urls-content-using-php-curl.html
----------------------------------------------------------------------------------------------------

(1) (Reply)

closed / Malvertising: Why Cryptocurrency Miner On Android Are Dangerous / Links To New Web Development Jobs In Nigeria And The Skills Required

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.