Home  >  Article  >  Backend Development  >  [转]php 处置 csv文件

[转]php 处置 csv文件

WBOY
WBOYOriginal
2016-06-13 11:15:30779browse

[转]php 处理 csv文件


导入模板

?

<?phpif (isset($_POST['import'])){        $file = $_FILES['csv_goods'];        $file_type = substr(strstr($file['name'],'.'),1);        // 检查文件格式    if ($file_type != 'csv'){        echo '文件格式不对,请重新上传!';        exit;    }    $handle = fopen($file['tmp_name'],"r");    $file_encoding = mb_detect_encoding($handle);        // 检查文件编码    if ($file_encoding != 'ASCII'){        echo '文件编码错误,请重新上传!';        exit;    }        $row = 0;    while ($data = fgetcsv($handle,1000,',')){        //echo "<font color=red>$row";  //可以知道总共有多少行        $row++;        if ($row == 1)        continue;        $num = count($data);        // 这里会依次输出每行当中每个单元格的数据        for ($i=0; $i";            // 在这里对数据进行处理        }    }        fclose($handle);}

?

Statement:
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