Home > Backend Development > PHP Tutorial > Use a PHP program to directly call the content instance of a text file_PHP tutorial

Use a PHP program to directly call the content instance of a text file_PHP tutorial

WBOY
Release: 2016-07-13 10:31:36
Original
937 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 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:

使用PHP程序直接调用文本文件的内容实例 帮客之家

$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:

Use a PHP program to directly call the content instance of a text file_PHP tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/762038.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