{"id":481,"date":"2019-03-14T11:00:13","date_gmt":"2019-03-14T10:00:13","guid":{"rendered":"https:\/\/bastienmalahieude.fr\/?p=481"},"modified":"2019-03-02T11:48:41","modified_gmt":"2019-03-02T10:48:41","slug":"importer-un-fichier-csv-en-tableau-php","status":"publish","type":"post","link":"https:\/\/bastienmalahieude.fr\/en\/importer-un-fichier-csv-en-tableau-php\/","title":{"rendered":"Import a CSV file into a PHP array"},"content":{"rendered":"
array(2) {\n [0]=>\n array(4) {\n [\"first name\"]=>\n string(7) \"Bastien\"\n [\"last name\"]=>\n string(10) \"Malahieude\"\n [\"phone\"]=>\n string(17) \"06 XX XX XX XX XX\"\n [\"email\"]=>\n string(28) \"contact@bastienmalahieude.fr\"\n }\n [1]=>\n array(4) {\n [\"first name\"]=>\n string(4) \"John\"\n [\"last name\"]=>\n string(3) \"Doe\"\n [\"phone\"]=>\n string(17) \"06 XX XX XX XX XX\"\n [\"email\"]=>\n string(11) \"john@doe.fr\"\n }\n}\n<\/pre>\n
<\/p>\n
For that we will create an\u00a0import_csv_to_array<\/em>\u00a0function\u00a0which reads the data from a file and returns a PHP array. This function takes two parameters, but only one is mandatory:<\/p>\n
\n
$ file<\/strong>\u00a0: This parameter is the path to the file.<\/li>\n
$ enclosure:<\/strong>\u00a0The character that surrounds strings.<\/li>\n<\/ul>\n
function import_csv_to_array($file,$enclosure = '\"')\r\n{\r\n\/\/ @TODO Do something here\r\n}<\/pre>\n