Load CSV File Into PHP 1-d Array

Loads a CSV file into a 1-d array. The csv file is a flat file, has no line breaks, elements are only separated by commas.

$array = explode(",", file_get_contents('csvfile.csv'));

Example:

csvfile.csv
Classic Collections,Abilene,TX 79602,(325) 672-0000,Fabulous Finds,Abilene,TX 79601,(325) 677-0000,Honeycomb Tree,Abilene,TX 79601,(325) 338-8000

PHP:
$array = explode(",", file_get_contents('csvfile.csv'));

Produces the following array:
Array (
    [0] => Classic Collections
    [1] => Abilene
    [2] => TX 79602
    [3] => (325) 672-0000
    [4] => Fabulous Finds
    [5] => Abilene
    [6] => TX 79601
    [7] => (325) 677-0000
    [8] => Honeycomb Tree
    [9] => Abilene
    [10] => TX 79601
    [11] => (325) 338-8000 )

 

Copyright © Lage.us Website Development | Disclaimer | Privacy Policy | Terms of Use