How to read the contents of a file into a string in PHP

- by

file_get_contents() can help us here. It reads a file and stores it in a string. Can be used with local files, as well as online content:

$myLocalFile = file_get_contents('myfile.html');
$myOnlineFile = file_get_contents('');

echo myOnline File; // would display the actual website

This is different from the file() function which reads the contents of a file into an array.

Add your voice!

This site uses Akismet to reduce spam. Learn how your comment data is processed.