Heim  >  Artikel  >  Backend-Entwicklung  >  [转]php 处置 csv文件

[转]php 处置 csv文件

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

[转]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);}

?

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn