File to String - Simple

Submitted by:David Villa

Date added:13 April, 2011


Reading a file to a string couldn't be easier than using the file_get_contents() function. Simple pass the name of the file (with path) and optional parameters

Tags: file to string

Code Snippet:

// ********************************
// basic example
$homepage = file_get_contents('');
$localfile = file_get_contents('config.ini');

// ********************************
// Get a file using the include path
// Below PHP 5
$file = file_get_contents('./people.txt', true);
// PHP 5 and above
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);