Welcome, Guest: Join Kenyans247 Log In!

Stats: 291 Members, 13,551 topics and 65 posts Date:  Friday 30 October 2020 at 10:39 AM
Popular & Trending NewestFeatured Links ClassifiedDirectoryLivescoresLive Kenyan TVLive Kenyan Radio Follow Us Like Us

About Us Terms & Conditions Privacy Policy FAQ's Disclaimer Copyright Contact Us Advertise With Us Download K247 APP Marketplace Moderator Policy We Are Hiring Kenya Radio and TV Stations Listen and Watch Live Letter From the C.E.O Kenya Radio Stations Live Kenya TV Stations Live Kenya - Newspapers and News Sites and popular blog Forum Rules

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

66 people viewed

Can Babies Get The Coronavirus Disease? Php: Get The Contents Of A Web Page, Rss Feed, Or Xml File Into A String Variabl How To Talk To Children About The Coronavirus Pandemic What Books Best Depict The Culture Of Burundi? How Do They Do It So Well?
(Go Down) (» Reply topic)
PHP: Get the contents of a web page, RSS feed, or XML file into a string variabl by Kenyans247(1): 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.

0 Shares 0 Like •

(» Go Up)

You must Sign in or Sign Up to post content

For you to post content on this website you have to log in or register, it only take few minute to create account

Go Up

Recommended for you

What Is The Best Thing About The Country Of Nigeria? What Is The Best Thing About The City Of Dar Es Salaam Tanzania? Can Antibiotics Treat The Coronavirus Disease? Can Babies Get The Coronavirus Disease?

Currently: 1 guest(s) reading this article

Sections: Kenyans247 ads, Africa, Family, K247 Intelligence, Diaspora, Programing, Art, Graphics & Video, Universities, Building/Architecture, Innovation, Gossip, Music/Radio, K247 TV, TV/Movies, Poetry, Burundi Forum, Somalia Forum, Rwanda Forum, South Sudan Forum, Tanzania Forum,

About Us | Terms & Conditions | Privacy Policy | FAQ's | Disclaimer | Copyright | Contact Us | Advertise With Us | Download K247 APP | Marketplace | Moderator Policy | We Are Hiring | Kenya Radio and TV Stations Listen and Watch Live | Letter From the C.E.O | Kenya Radio Stations Live | Kenya TV Stations Live | Kenya - Newspapers and News Sites and popular blog | Forum Rules | Featured LinksFollow Us on TwitterLike Us on Facebook

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.