How does PHP read the file into an array?

Source: Internet
Author: User
Tags rtrim
PHP read files can read files from the current server or remote server. The steps are: Open the file, read the file, and close the file. This article mainly describes how PHP will read the file in the array? , which involves the manipulation of files and strings by functions such as file and RTrim in PHP . The specific analysis is as follows:

PHP can be read into the array through the file () function, the elements of the array is each line of the file, the files () function by "\ n" by the row split file saved to the array, so each element of the array is "\ n" end, we can be removed by the RTrim () function.

The RTrim () function removes white space characters or other predefined characters to the right of the string.

PHP reads a file into an array of instance code

<?php $lines = File ("/tmp/file.txt"), foreach ($lines as $line) {$line = RTrim ($line); print ("$line \ n");//More Statem Ents ...}? >
Related Article

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.