댓글 검색 목록

[php] 배열로부터 CSV화일 만들기

페이지 정보

작성자 운영자 작성일 15-05-07 18:59 조회 2,135 댓글 0

PHP Function :

function generateCsv($data, $delimiter = ',', $enclosure = '"') {

       $handle = fopen('php://temp', 'r+');

       foreach ($data as $line) {

               fputcsv($handle, $line, $delimiter, $enclosure);

       }

       rewind($handle);

       while (!feof($handle)) {

               $contents .= fread($handle, 8192);

       }

       fclose($handle);

       return $contents;

 

사용 :

$data = array(

       array(1, 2, 4),

       array('test string', 'test, literal, comma', 'test literal "quotes"'),

);

 

echo generateCsv($data); 

댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.