How to use php to directly call the text file content: first, open a text file on the server through the file function, the returned $ myFile will become the handle of the file operation, and then use the circular command, extract and print the content of each row in the file. The idea of programming should first use SyntaxHighlighter. all (); how to use php to directly call the content of a text file: first, use the file function to open a text file on the server, and the $ myFile returned will become the handle for this file operation, then, execute the circular command to retrieve and print the content of each row in the file.
Programming Logic
The first function to be used is fi1e. This function is similar to readfile (). in different places, the file function reads all the content in the file, and output to the array variables, each row is a separate array element. Use the file function to open a data.txt file. the content of the data.txt file is:
First Line 1
Row 2
Row 3
The statement for opening a file is $ myFile = file ("data.txt"). $ myFile is an array variable.
Then print the content of each element of the array through the loop command loop in the array. here the count () function is used
Obtains the number of array elements. Print ($ myFile [$ index]. "").
Creation steps
1. use the file function to open a file
$ MyFile = file ("data.txt ");
2. loop through the array and print the elements of the array
Here
For ($ index = 0; $ index
For ($ index = 0; $ index {
Print ($ myFile [$ index]. "<br> ");
}
At the same time, the elements in the array are printed out.
3. program code
Call text file content
// Print each line while opening the file
$ MyFile = file ("data.txt ");
For ($ index = 0; $ index {
Print ($ myFile & 91; $ index & 93 ;."
");
}
?>