Kenyans247 Forum

Welcome, Guest: Join Kenyans247 LOGIN!

Stats: 223 Members, 11,345 topics and 65 posts Date: Friday 03 April 2020 at 10:26 AM
TrendingRecentNewestClassifiedDirectoryLivescoresLive Kenyan TVLive Kenyan Radio

PHP: Get the contents of a web page, RSS feed, or XML file into a string variabl

Kenyans247 / Science/Technology / Computers / PHP: Get the contents of a web page, RSS feed, or XML file into a string variabl (17 View's)

What Books Best Depict The Culture Of Burundi? How Do They Do It So Well? Matiang'i Declares Ruthless Operation To Flash Out Drug Peddlers At The Coast All You Need To Know About The Clash Between Kenyatta And Ruto What Is The Best Thing About The City Of Nairobi Kenya?
(Go Down) (» Reply topic)
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:



function get_url_contents($url){
$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);
curl_close($crl);
return $ret;
}
You should now have the contents of the website in a string variable. Note that this doesn’t pull down the supporting files such as javascript or CSS. You will have to further parse the page and retrieve those seperately if you need the whole thing.

(» Reply topic) (» Go Up)

Recommended for you

» How To Talk To Children About The Coronavirus Pandemic » Matiang'i Declares Ruthless Operation To Flash Out Drug Peddlers At The Coast » What Books Best Depict The Culture Of Burundi? How Do They Do It So Well? » Britain's Got Talent The Champions: Who's Taking Part?
Viewing this topic:
1 guest(s) viewing this topic

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.