|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Non-Member
![]() ![]() ![]() Join Date: Nov 2003
Location: here
Posts: 259
|
Sorting and Inserting a CSV
Now - I am completely new to this, bear in mind. Not to PHP - but to this. Well, an up and coming project will require me to download a pretty messy CSV file, sort it into a local format and upload and insert it into a database.
Could someone outline the pre-requisite knowledge I would require to go about something like this, any good resources/tutorials that delve into this sort of thing. Thanks kindly. Cristiano |
|
|
|
|
|
#2 |
|
PHP manual bot
![]() Join Date: Oct 2003
Location: Germany
Posts: 2,196
|
I don't exactly see what your problem is? You get the file into an array with file, then go trough it (foreach) and explode every value into a second array with all values. Then you jungle with your new, multi dimensional array and generate your queries out of it.
PHP Code:
|
|
|
|
|
|
#3 |
|
Non-Member
![]() ![]() ![]() Join Date: Nov 2003
Location: here
Posts: 259
|
OK thanks - I hadn't had any experience with this before, and the explode function either. What does this do exactly?
|
|
|
|
|
|
#4 | |
|
PHP manual bot
![]() Join Date: Oct 2003
Location: Germany
Posts: 2,196
|
I didn't place a link on it's name for no reason, check it out.
![]() Quote:
|
|
|
|
|
|
|
#5 |
|
SitePoint Member
Join Date: Dec 2000
Posts: 6
|
You say that you already have it in CSV format? Why not use fgetscv?
http://us4.php.net/manual/en/function.fgetcsv.php The example there is pretty good. PHP Code:
|
|
|
|
|
|
#6 |
|
PHP manual bot
![]() Join Date: Oct 2003
Location: Germany
Posts: 2,196
|
I would only use fgetcsv if the CSV file is quite big, then only storing part of it in memory would be a lot better then having it all. But if you want speed and you've got enough memory and/or you will not run this a lot (or at peak times) then the file, explode way should work good enough.
|
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 23:00.










Linear Mode
