PHP with Fgets read the string, it would have encountered a newline stop reading, but the actual will be in the back of the string to read something, I feel is the cause of Windows line, \ r \ n, this may be the reason, there is always a space, resulting in the use of the string I always error.
In a try, mainly using fgetc, and case, found that the end of the string has two ASCII 0 characters, these two things caused the string after the space.
while (!feof ($myfile)) { $data 1 = fgets ($myfile); $i = strlen ($data 1); Str_replace (Array (' \ n ', ' \ R ', ' \n\r ', '), ' V ', $data 1); Switch ($data 1) {case 0: # code ... echo 0; break; Case Ten: Echo ten; break; Default: # code ... echo one; break; } echo $i; $i + +; echo "AA". $data 1. " AA "; echo "
"; echo "AA". substr ($data 1,0, $i-2). " AA "; echo "
"; }
So the decisive use of string intercept function, cut off the last two characters just fine.
$i = strlen ($data 1); echo "AA". substr ($data 1,0, $i-2). " AA ";
This will be read normally, but the last line of string will be followed by a space
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the PHP fgets function to read the extra space to solve, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.