Skip to content
PHP Logo

What alternative PHP function could be used instead of fopen() for reading a text file?

If you want to read a text file in PHP without using the fopen() function, you can use the file_get_contents() function. This function reads the entire contents of a file into a string, making it a simple alternative to fopen() for reading text files.

php
$file_contents = file_get_contents('textfile.txt');
echo $file_contents;