Read CSV file content PHP

This tutorial explains how to read data from the CSV file using the PHP code.The following code read all data from CSV file and return an array.


Please also refer the tutorial which explains how to bulk create wordpress post and bulk import magento products from CSV.

function readCSV()
    $options_arr = array();
    $images = 'doorsexport.csv';
    $handle = fopen($images, "r");
    $headers = false;
    if (empty($handle) === false) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            if (!$headers) {
                $headers[] = $data;
            } else {
                $options_arr[] = $data; 
    return $options_arr;

Share this Tutorial