Use PHP program to directly call text file content analysis_PHP tutorial

WBOY
Release: 2016-07-13 17:29:57
Original
1166 people have browsed it

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 the content of each line in the file 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

$myFile=file("data.txt");

 2. Loop through the array and print the elements of the array

Here, via

for($index=0;$index
for($index=0;$index ) {
                                                 🎜>
At the same time, print out the contents of the elements in the array.

 

3. Program code

Calling text file content


< ?
// Open the file and print each line
$myFile=file("data.txt");
for($index=0;$index {
print($myFile&91;$index&93;."
");
}
?>



http://www.bkjia.com/PHPjc/509211.html

truehttp: //www.bkjia.com/PHPjc/509211.htmlTechArticleHow 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 return $ myFile will become the handle of this file operation, and then through the loop...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template