Reading a file into a string in PHP

If you'd like to get the entire content of a file into a string then follow the way



// have your filename with path
$file_name = "yourfilename.ext";
$content_string = file_get_contents($file_name);
echo $content_string; // will display the content


want to display total chars in the file?


echo strlen($content_string);


To read file into array.


// have your filename with path
$file_name = "yourfilename.ext";
$content = file($filename);
foreach($content as $content_row)
echo $content_row;

0 comments



Some Links (off programming)