how to import CSV using zend

前端 未结 4 366
故里飘歌
故里飘歌 2021-02-04 09:36

How do I import CSV files using zend framework? Should I use zend_file_transfer or is there any special class that I have to look into? Also if I use zend_file_transfer is there

4条回答
  •  你的背包
    2021-02-04 10:22

    Here's a function that reads a csv file and returns an array of items that contain the first two column data values.

    This function could read a file of first_name,last_name for example.

    function processFile ($filename) {
        $rtn = array();
    
        if (($handle = fopen($filename, "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                $item = array();
                $item[] = $data[0];
                $item[] = $data[1];
                $rtn[] = $item;
            }
        }
        return $rtn;
     }
    

提交回复
热议问题