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 ...}? >