Home Create CSV File From Array With PHP

    Create CSV File From Array With PHP


    A comma-separated values (CSV) file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format. The following PHP function takes an array and either returns the data to a screen or writes the array contents as a CSV file. The non-standard implementation of the CSV format means you may have to play around with the output.

    PHP Function

    Sample use is as follows:

    If you’re looking for a more robust solution there’s plenty of CSV libraries available to handle more complex requirements.

    Shortt URL for this post: http://shor.tt/1XU7