douming4359 2016-06-02 10:25
浏览 136
已采纳

如何在php中获取CSV列值

I have an excel file suppose with column value "A B" what i want is to separate the values after the first space i.e A in another column and B in other. I used PHPEXCEL

<?php
 class SampleReadFilter implements PHPExcel_Reader_IReadFilter {
public function readCell($column, $row, $worksheetName = '') {
    // Read rows 1 to 10 and columns A to C only
    if ($row >= 1 && $row <= 7) {
       if (in_array($column,range('A','C'))) {
         return true;
       }
    }
    return false;
}
}
  • 写回答

1条回答 默认 最新

  • doumen5087 2016-06-02 11:07
    关注

    try this one

    <?php
    $row = 1;
    if (($handle = fopen("abc.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {        
            $username =  $data[0];
            $usernames  = explode(' ', $email);
            print($usernames[1]).'<br />';
    
    }
    fclose($handle);
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?