Browse - Programming Tips - php: load a file into a string

Date: 2018jun1
Language: php

Q.  php: load a file into a string

A.  To read a file from disk into a string?

$s = file_get_contents('my_file.txt'); # correct
Do NOT use readfile()
$s = readfile('my_file.txt'); # WRONG
readfile() will pass the file thru to the browser and put the number of byte info your string. There is probably a place for this function but I bet its used wrong more often than not.