How can PHP read the content of a txt file?

In PHP, you can use the file_get_contents() function to read the contents of a txt text file. Here is a simple example code:

$filename = 'file.txt';

$content = file_get_contents($filename);

echo $content;

In the code above, first the filename of the text file to be read is specified and assigned to the variable $filename. Then the file contents are read using the file_get_contents() function and stored in the variable $content. Finally, the file content is outputted using an echo statement.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds