Hướng dẫn readline in php w3schools
In this chapter we will teach you how to open, read, and close a file on the server. Show PHP Open File - fopen()A better method to open files is with the We will use the text file, "webdictionary.txt", during the lessons: AJAX = Asynchronous JavaScript and XML The first parameter of Example$myfile = fopen("webdictionary.txt", "r") or die("Unable to open
file!"); Run example » Tip: The The file may be opened in one of the following modes:
PHP Read File - fread()The The first parameter of The following PHP code reads the "webdictionary.txt" file to the end: fread($myfile,filesize("webdictionary.txt")); PHP Close File - fclose()The It's a good programming practice to close all files after you have finished with them. You don't want an open file running around on your server taking up resources! The $myfile = fopen("webdictionary.txt", "r"); PHP Read Single Line - fgets()The The example below outputs the first line of the "webdictionary.txt" file: Example$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!"); Run example » Note: After a call to the PHP Check End-Of-File - feof()The The The example below reads the "webdictionary.txt" file line by line, until end-of-file is reached: Example$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!"); Run example » PHP Read Single Character - fgetc()The The example below reads the "webdictionary.txt" file character by character, until end-of-file is reached: Example$myfile =
fopen("webdictionary.txt", "r") or die("Unable to open file!"); Run example » Note: After a call to the Complete PHP Filesystem ReferenceFor a complete reference of filesystem functions, go to our complete PHP Filesystem Reference. PHP Exercises |