Using PHP to directly invoke text file content Analysis _php tutorial

Source: Internet
Author: User
How to directly invoke the text file content in PHP: first through the file function to open a text file on the server, the returned $myfile will become the handle of the file operation, and then through the loop instruction, take out the contents of each line of the file and print out.

Programming Ideas

The first function to be used is fi1e, which is similar to ReadFile (), where the file function reads all the contents of the files and outputs them to the variable in the array, and each row is a separate array element. Open a Data.txt file using the file function, and the contents of the Data.txt file are:

First row 1

Second row 2

Third row 3

The statement to open the file is: $myFile =file ("Data.txt"), when $myfile is an array variable.

The contents of each element of the array are then printed by looping through the loop instruction in the arrays, and the function of count () is used here to

Gets the number of array elements. The statement that prints the contents of the array is: print ($myFile [$index]. " ")。

Authoring steps

  First, use the file function to open files

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

  Second, loop through the array, print the elements of the array

Here, by

for ($index =0; $index
for ($index =0; $index {
Print ($myFile [$index]. " < br> ");
}

Prints the contents of the elements in the array at the same time.

  Third, the program code



Invoke text file contents


Open a 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 www.bkjia.com true http://www.bkjia.com/PHPjc/509211.html techarticle how to directly invoke the text file content in PHP: first through the file function to open a text file on the server, the returned $myfile will become the handle of the operation of the files, and then through ...

  • 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.