PHP reads the contents of the txt file and assigns it to the array code. The content of the file 2010-12-15.txt is as follows: the Copy code is as follows:
The code is as follows:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
T01
T02
T03
T04
T05
T06
T07
T08
T09
T10
T11
T12
T13
T14
T15
T16
The idea is as follows: use file_get_contents () to get the content of the txt file, and then convert the obtained string to an array through explode. You can use the count () function to obtain the array length.
PHP Code
The code is as follows:
$ File = '2010-12-15.txt ';
$ Content = file_get_contents ($ file );
// Echo $ content;
$ Array = explode ("\ r \ n", $ content );
// Print_r ($ array );
For ($ I = 0; $ I <count ($ array); $ I ++)
{
Echo $ array [$ I]. '<br/> /〉';
}
Line breaks in txt documents
In a regular expression, \ n indicates newline, and \ r indicates carriage return (that is, this leads to an idiot Chinese translation "press enter. When processing String or console output, line breaks can be applied to any String or console output.
However, in txt, none of them are the standard line breaks. Only the combined \ r \ n is the line feed (this is the case for the default line breaks of windows ).
It means \ r knocks on the carriage return, indicating that this line is over, the cursor goes back to the header, and then \ n moves down a new line.
Because of this, when I used lift () to search for a txt document with a regular expression, I couldn't find the problem at all.
About file_get_contents ()
The file_get_contents () function reads the entire file into a string.
The file_get_contents () function is the preferred method for reading the file content into a string. If supported by the operating system, the memory ing technology will be used to enhance the performance.
The pipeline code is as follows: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 19 20 21 22 23 24 T01 T02 T03 T04 T05 T06 T07 T08 T09 T10 t11...