php 读取execl

$path './country.xls';

$file fopen($path'r');
//标题行读取(第一行)
$row fgets($file);
$row explode("\t"$row);
$title array();
foreach($row as $k => $v) {
    $title[$k] = str_replace("\n"''$v);
}
//内容读取
$data array();
$count = 0;
while(!feof($file)) {
    $row fgets($file);
    $row explode("\t"$row);
    if(!$row[0]) continue;//去除最后一行
    foreach($title as $k => $v) {
        $data[$count][$title[$k]] = $row[$k];
    }
    $count ++;
}
fclose($file);
echo '<pre>';
print_r($data);
posted @ 2020-03-20 16:03  星云惊蛰  阅读(71)  评论(0)    收藏  举报