The contents of the 2010-12-15.txt file are as follows:
Copy CodeThe code is as follows:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21st
22
23
24
T01
T02
T03
T04
T05
T06
T07
T08
T09
T10
T11
T12
T13
T14
T15
T16
Here's the idea: Use File_get_contents () to get the contents of the TXT file, and then convert the obtained string to an array by explode (). You can use the count () function to get the array length.
PHP Code
Copy CodeThe 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/〉 ';
}
About line breaks in TXT documents
In the regular expression, there is a \ n is the meaning of newline, and a \ r is carriage return (that is, this led to the idiot Chinese translation "return") meaning. When working with a string or console output, it can be wrapped in any line.
But in TXT, which is not the standard line, only the combination of \ r \ n is a newline (for the entire Windows default line-wrapping, this is the case).
It means that the line is over, the cursor goes back to the head, and then it moves down a line to a new line.
Because of this, I used scanner () with regular expressions to search for TXT documents, once helpless, there is no 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 contents of a file into a string. If supported by the operating system, memory-mapping techniques are also used to enhance performance.
http://www.bkjia.com/PHPjc/324445.html www.bkjia.com true http://www.bkjia.com/PHPjc/324445.html techarticle the file contents of 2010-12-15.txt are as follows: Copy the code code as follows: in Geneva, the following is a one-to-one-ten-a-T01 T02 T03 T04 T05 T06 T07 T08 T09 T10 T11 ...