如果所有csv数据都在一个单独的行中,如何逐行获取CSV数据?

时间:2015-01-07 12:32:26

标签: php csv

我需要这个:

Array
(
    [0] => Customer First Name
    [1] => Customer Last Name
    [2] => Date
    [3] => Is Anonymous
    [4] => Rating
    [5] => Title
    [6] => Review
    [7] => EMail

)

Array
(
    [0] => TODD
    [1] => JACKMAN
    [2] => 6/17/13
    [3] => FALSE
    [4] => 5
    [5] => Outstanding service as always!
    [6] => Outstanding service as always!
    [7] => abc@al.com

)

Array
(
    [0] => Gary
    [1] => Peters
    [2] => 6/19/13
    [3] => FALSE
    [4] => 5
    [5] => From my description Ari suggested...
    [6] => From my description Ari suggested what the problem might be. It was as he suspected. Got a replacement part at the best price. Installation was prompt and successful. Still one of the best places to go for auto repair.
    [7] => abc@test.com

)

但我得到了:

Array
(
    [0] => Customer First Name
    [1] => Customer Last Name
    [2] => Date
    [3] => Is Anonymous
    [4] => Rating
    [5] => Title
    [6] => Review
    [7] => EMail
TODD
    [8] => hjk
    [9] => JACKMAN
    [10] => 6/17/13
    [11] => FALSE
    [12] => 5
    [13] => Outstanding service as always!
    [14] => Outstanding service as always!
    [15] => abc@al.com
Kliop
    [16] => Gary
    [17] => Peters
    [18] => 6/19/13
    [19] => FALSE
    [20] => 5
    [21] => From my description Ari suggested...
    [22] => From my description Ari suggested what the problem might be. It was as he suspected. Got a replacement part at the best price. Installation was prompt and successful. Still one of the best places to go for auto repair.
    [23] => abc@test.com

)

请帮帮我......

1 个答案:

答案 0 :(得分:1)

请尝试

$lines = file('test.csv');

    foreach ($lines as $line_num => $line) {
         $data = explode(',',$line);
         echo "<pre>";print_r($data);
    }

希望对你有所帮助