To invoke a content instance of a text file directly using a PHP program

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.