How to use PHP to directly call the content of a text file: First open a text file on the server through the file function, and the returned $myFile will become the handle of the file operation, and then use the loop instruction to take out each file in the file. One line of content and print it out.
Programming ideas
The first function to use is fi1e. This function is similar to readfile(). The difference is that the file function reads all the contents of the file and outputs it to the variable of the array. Each line 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
Second line 2
Third line 3
The statement to open the file is: $myFile=file("data.txt"); at this time $myFile is an array variable.
Then use the loop instruction to loop through the array to print out the contents of each element of the array. The count() function used here is used to
Get the number of array elements. The statement to print the contents of the array is: print($myFile[$index]." ").
Creation steps
1. Use the file function to open the file
The following is a quote:
$myFile=file("data.txt");
2. Loop through the array and print the elements of the array
Here, via
The following is a quote:
At the same time, print out the contents of the elements in the array.
3. Program code
The following is a quote: