I read the contents of a txt file line by line, but the first line of each file is always not recognized correctly. how can I do this? {Code ...} txt file content: {code ...} the length of the first number in the first row of the file is always incorrect each time you read the file. There should be an invisible string ..: {code ...} I read the contents of a txt file line by line,
However, the first line of each file cannot be correctly identified,
What can I do?
$rTxt = fopen( $sTxt ,"r" ); while( $str = fgets($rTxt) ) { $arr = explode( ',' , $str ); Var_Dump( $arr[0] ); } fclose( $rTxt );
Txt file content:
1393592460,10680,10660,10650,10720,6040,3.227103E+08,0,0,108,4746,0,01393592520,10656,10697,10656,10701,4888,2.612444E+08,0,0,203,6858,0,01393592580,10697,10672,10672,10700,1294,6.911194E+07,0,0,281,7086,0,01393592640,10671,10667,10661,10675,1706,9.101747E+07,0,0,354,7590,0,01393592700,10669,10650,10648,10670,2340,1.246486E+08,0,0,448,8664,0,01393592760,10652,10640,10632,10656,1938,1.031578E+08,0,0,545,9282,0,01393592820,10641,10657,10641,10662,1746,9.297165E+07,0,0,631,8922,0,0......
The length of the first number in the first row of the file is always incorrect each time you read the file. There should be an invisible string ..:
string(13) "1393592460"string(10) "1393592520"string(10) "1393592580"string(10) "1393592640"
Reply content:
I read the contents of a txt file line by line,
However, the first line of each file cannot be correctly identified,
What can I do?
$rTxt = fopen( $sTxt ,"r" ); while( $str = fgets($rTxt) ) { $arr = explode( ',' , $str ); Var_Dump( $arr[0] ); } fclose( $rTxt );
Txt file content:
1393592460,10680,10660,10650,10720,6040,3.227103E+08,0,0,108,4746,0,01393592520,10656,10697,10656,10701,4888,2.612444E+08,0,0,203,6858,0,01393592580,10697,10672,10672,10700,1294,6.911194E+07,0,0,281,7086,0,01393592640,10671,10667,10661,10675,1706,9.101747E+07,0,0,354,7590,0,01393592700,10669,10650,10648,10670,2340,1.246486E+08,0,0,448,8664,0,01393592760,10652,10640,10632,10656,1938,1.031578E+08,0,0,545,9282,0,01393592820,10641,10657,10641,10662,1746,9.297165E+07,0,0,631,8922,0,0......
The length of the first number in the first row of the file is always incorrect each time you read the file. There should be an invisible string ..:
string(13) "1393592460"string(10) "1393592520"string(10) "1393592580"string(10) "1393592640"
It is probably a UTF-8 bom character.
Reference SO How to remove multiple UTF-8 BOM sequences
//Remove UTF8 Bomfunction remove_utf8_bom($text){ $bom = pack('H*','EFBBBF'); $text = preg_replace("/^$bom/", '', $text); return $text;}
Use this function to process your first line.
Want to know