| Viewing this topic:
1 guest(s) viewing this topic
Live Kenyan TV •
Live Kenyan Radio
|PHP: Get the contents of a web page, RSS feed, or XML file into a string variabl by Kenyans247(m): Sun 22, March, 2020 10:52am|
You will often have the need to access data that resides on another server, whether you are writing an online RSS aggregator or doing screen scraping for a searching mechanism. PHP makes pulling this data into a string variable an extremely simple process.
You can go with the really short method:
$url = “https://www.howtogeek.com”;
$str = file_get_contents($url);
The only problem with that method is that some web hosts have url access blocked in the file methods, for security reasons. You may be able to use this workaround method instead:
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
Sections: International Forum, Environment, Homepage, Food, Autos, Technology Market, Phones, Programing, Education, Building/Architecture, TV/Movies, Gaming, Literature, Forum Games, Jokes Etc, Rwanda Forum, Ugandan Forum, Burundi Forum, South Sudan Forum, Somalia Forum,Kenyans247 - Copyright © 2019 - 2020 Sande Kennedy. All rights reserved. See How To Advertise.
Disclaimer: Every Kenyans247 member is solely responsible for anything that he/she posts or uploads on Kenyans247.