We can see that someone adds a 'or any halfwidth symbol to the front of a Chinese character string to let the bug remove it, but this is too troublesome. Finally, we can find a function to simulate the fgetcsv function.
Copy codeThe Code is as follows:
Function _ fgetcsv (& $ handle, $ length = null, $ d = ',', $ e = '"'){
$ D = preg_quote ($ d );
$ E = preg_quote ($ e );
$ _ Line = "";
$ Eof = false;
While ($ eof! = True ){
$ _ Line. = (empty ($ length )? Fgets ($ handle): fgets ($ handle, $ length ));
$ Itemcnt = preg_match_all ('/'. $ e. '/', $ _ line, $ dummy );
If ($ itemcnt % 2 = 0)
$ Eof = true;
}
$ _ Csv_line = preg_replace ('/(? : | [])? $/', $ D, trim ($ _ line ));
$ _ Csv_pattern = '/('. $ e. '[^'. $ e. '] * (? :'. $ E. $ e. '[^ '. $ e. '] *) *'. $ e. '| [^ '. $ d. '] *)'. $ d. '/';
Preg_match_all ($ _ csv_pattern, $ _ csv_line, $ _ csv_matches );
$ _ Csv_data = $ _ csv_matches [1];
For ($ _ csv_ I = 0; $ _ csv_ I <count ($ _ csv_data); $ _ csv_ I ++ ){
$ _ Csv_data [$ _ csv_ I] = preg_replace ('/^ '. $ e. '(. *)'. $ e. '$/s',' $ 1', $ _ csv_data [$ _ csv_ I]);
$ _ Csv_data [$ _ csv_ I] = str_replace ($ e. $ e, $ e, $ _ csv_data [$ _ csv_ I]);
}
Return empty ($ _ line )? False: $ _ csv_data;
}