php读取CSV文件

<?php

$result = _import_csv('./ceshi.csv');

echo "<pre>";

print_r($result);

echo "</pre>";

function  _import_csv($filename){

$return = array();

$row = 0;

if (($handle = fopen($filename,"r" )) !==  FALSE ) {

    while (($data = fgetcsv($handle,1000)) !==  FALSE ) {

    if($row>=1){ //过滤第一行标题

    $num = count($data);

        for ($i=0;$i<$num;$i++) {

        $data[$i] = trim($data[$i]);

        if($data[$i]==''){ //如果为空,则跳过此行继续循环

        continue;

        }else{

        $return[$row][$i] = $data[$i];

        }

      }

    }

      $row++;

    }

    fclose($handle);

    return $return;

}else{

return $return;

}

}

?>

csv文件格式如下,文件名ceshi.csv
姓名 账号
action 1
xing 2
dong 3