Stats: 3,189,650 members, 7,937,936 topics. Date: Monday, 02 September 2024 at 02:27 PM |
Nairaland Forum / Science/Technology / Programming / Download A Url’s Content Using PHP Curl (983 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)
Get Current Page URL In PHP / First / My stack. HTML, CSS, JavaScript, Python, MySQL.
(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. 9 |