0

我正在搜索 PHP 代码以在 PHP 的帮助下从 CSV 获取行/列。什么是重要的:

我想在代码中添加行/列的编号来获取它的名称!

ISO_COUNTRY_CODE,CNT_POSTAL_CODE,ORDER1_ADMIN_TYP_1112,ORDER2_ADMIN_TYP_1113,ORDER8_ADMIN_TYP_1119,BUILTUP_ID
AND,7,0,0,7,41
ARG,1970,25,0,514,4076
AUS,2612,9,0,10978,4597
AUT,2213,9,95,2354,10304
BEL,1148,3,11,589,3781
BGR,4507,28,0,264,5375
4

1 回答 1

0

你可以这样做-

$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}

有关更多信息,您可以查看: http: //php.net/manual/en/function.fgetcsv.php

于 2013-08-06T11:54:40.170 回答