Gen. partnerAlgotech

File_get_contents

Either function can be used to load a local file from disk:

|
September 11, 2019

The file_get_contents function is used to read a file and put its contents into a variable. This function is similar to the include function, but unlike include, it can retrieve remote files on the Internet and transfer their contents via variables.

Sample

Either function can be used to load a local file from disk:

$news = file_get_contents('news.html');
echo 'Current news:<br>' . $news;

Or from a remote URL:

$page = file_get_contents('https://www.google.com');
echo $page;

When retrieving a URL, we can download any address and get its contents as a string into a variable. In the case of HTML, this is the source code.

The page is rendered incorrectly

This is because the HTML code is passed exactly as it is placed on the URL.

If the path to the image is for example <img src="kocka.png">, then this file may not exist in the context of our server, so we need to correct the path to for example: <img src="https://server.cz/kocka.png">.

Loading comments...

Stay in the loop

Subscribe to our newsletter and get the latest cybersecurity news delivered straight to your inbox.

Your data is safe. You can unsubscribe from the newsletter at any time.