Need to implement csv or xls import into Application created using CodeIgniter. Is there any library for this? Any suggestion appreciated.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Well don't mind me, I just modified ajmedway's library to include delimiters just in case you wanted to get data from lets say TSV or pipes delimited files. If you want plain old CSV his is just fine.
Call in controller:
This is an improved version of raheel shan's accepted answer - I edited his answer but my edit was rejected, however it is an important change...
When parsing each data row, it is not wise to use
explode()
on the comma as this does not handle quote-encased strings that contain commas. Explode breaks those strings into substrings and gives extra array elements in$values
, so this check fails:Instead, PHP has a purpose-built method to handle this; str_getcsv(). I have updated the original answer code accordingly.
The CSV Reader library:
Controller method:
And this is the view:
Here is an easy way to do this. I don't know what people do but i use this
This is my csv reader library
And controller method
And this is view
Reference Here
This is an improved version for empty lines and extra spaces and tabs...
class CSVReader {
} ?>