php fgetcsv reads csv file code (1/2)_PHP tutorial

WBOY
Release: 2016-07-20 11:07:57
Original
1071 people have browsed it

php tutorial fgetcsv read csv file code

function get_csv_contents( $file_target ){

$handle = fopen( $file_target, 'r');

while ($data = fgetcsv($handle, 1000, ",")) {

$num = count($data);
echo "

$num fields in line $ row:
n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c]. "< br>n";;
            /*echo getUTFString($data[$c])*/                                                                                        
array fgetcsv ( int handle [, int length [, string delimiter [, string enclosure]]] )


handle

one by fopen( ), popen() or fsockopen().

length (optional)

must be greater than the longest line in the CVS file. This parameter is optional in PHP 5. If this parameter is omitted (set to 0 in PHP 5.0.4 and later versions), there is no limit to the length, but execution efficiency may be affected.


delimiter (optional)
Set the field delimiter (only one character allowed), the default value is comma.

enclosure (optional)
Set the field surround character (only one character allowed), the default value is double quotes. This parameter was added in PHP 4.3.0.


Similar to fgets(), except that fgetcsv() parses the read line and finds the fields in CSV format and returns an array containing those fields.

fgetcsv() returns FALSE on error, including when the end of file is encountered.

1 2


http://www.bkjia.com/PHPjc/444919.html


www.bkjia.com

true

TechArticlephp tutorial fgetcsv reading csv file code function get_csv_contents( $file_target ){ $handle = fopen( $file_target, ' r'); while ($data = fgetcsv($handle, 1000, ,)) { $num = count($dat...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!