How to use PHP to invoke the contents of a text file directly: 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 through the loop instruction, take out the contents of each line in the file and print it out.
Programming Ideas
The first function to use is fi1e, a function similar to ReadFile (), where the file function is read out in all of the files and output to the variable of the array, each row is a separate array element. To open a Data.txt file using the file function, the contents of the Data.txt files are:
First Line 1
Second Line 2
Third Line 3
The statement that opens the file is: $myFile =file ("Data.txt"), at which point $myfile is an array variable.
Then through the loop of the loop instruction in the array, print the contents of each element of the group, where the count () function is used to
Gets the number of array elements. The statement that prints the contents of the array is: print ($myFile [$index]. ")。
Authoring steps
Opening files using the file function
The following is a reference fragment:
$myFile =file ("Data.txt");
Second, in the array loop, print the elements of the array
Here, through
The following is a reference fragment:
At the same time, print out the contents of the elements in the array.
Third, the program code
The following is a reference fragment: