Create a CSV File for a user in PHP

前端 未结 19 2041
故里飘歌
故里飘歌 2020-11-22 11:52

I have data in a MySQL database. I am sending the user a URL to get their data out as a CSV file.

I have the e-mailing of the link, MySQL query, etc. covered.

<
19条回答
  •  没有蜡笔的小新
    2020-11-22 12:27

    How to write in CSV file using PHP script? Actually I was also searching for that too. It is kind of easy task with PHP. fputs(handler, content) - this function works efficiently for me. First you need to open the file in which you need to write content using fopen($CSVFileName, ‘wb’).

    $CSVFileName = “test.csv”;
    $fp = fopen($CSVFileName, ‘wb’);
    
    //Multiple iterations to append the data using function fputs()
    foreach ($csv_post as $temp)
    {
        $line = “”;
        $line .= “Content 1″ . $comma . “$temp” . $comma . “Content 2″ . $comma . “16/10/2012″.$comma;
        $line .= “\n”;
        fputs($fp, $line);
    }
    

提交回复
热议问题