|
| HOW TO READ FILES INTO A STRING USING THE file_get_contents() FUNCTION IN PHP
PHP provides the simple file_get_contents() function to read the entire contents of a file into one long string. In it's simplest form, this function takes the file or a url as parameter.
Example :
<?
$myFile="test.txt";
$data=file_get_contents($myFile);
?>
You can also use this file_get_contents() function on urls as well and not just files as in the example below.
Example :
<?
$myFile="http://www.somesite.com/somepage.html";
$data=file_get_contents($myFile);
?>
The entire contents of the file is now stored in variable $data. If you echo $data, you will get the entire contents of this file outputted to your screen.
|
|