I would use fgetcsv() (http://php.net/manual/en/function.fgetcsv.php).
It should handle quoted strings that have commas in them.
Alternatively, your client can export with an alternative delimiter
such as a pipe "|" character.
Then you just do something like:
$content = file_get_contents('somefile.txt');
$lines = explode("\n", $content);
foreach( $lines as $line )
{
$values = explode("|", $line);
// insert values wherever
}
- Larry
On Thu, Feb 3, 2011 at 10:02 AM, Rusty Fincke <[email protected]> wrote:
> Hi there! I was wondering if anyone had thoughts, pointers, links or help
> on my situation. I'm looking for a php script that will import csv data in
> mysql. I need a client to be able to upload a file (CSV) from their
> computer and then have it import the CSV into MySQL. I've found a solution
> that works here: http://www.legend.ws/blog/tips-tricks/csv-php-mysql-import/
>
> However, this doesn't allow for fields that include commas that are
> contained in double quotes. The client's CSV file might have fields that
> are dollar amounts with commas in it ( $5,250 ) and it also imports a
> comment field where the CSV might use a comma in the comment field. I've
> been pouring over this for some time and I just can't seem to figure out
> what I need to add to this script to include for this situation. Something
> tells me it's something simple but I'm just not getting it. FYI - I don't
> need the file upload solution and code to get me to the import requirement,
> I just can't get the import to work correctly when coming across fields that
> include commas.
>
> Thought I would reach out to the refresh group and see if anyone has any
> advice or dealt with this before.
>
> Thanks,
>
> Rusty Fincke
> [email protected]
>
> --
> Our Web site: http://www.RefreshAustin.org/
>
> You received this message because you are subscribed to the Google Groups
> "Refresh Austin" group.
>
> [ Posting ]
> To post to this group, send email to [email protected]
> Job-related postings should follow http://tr.im/refreshaustinjobspolicy
> We do not accept job posts from recruiters.
>
> [ Unsubscribe ]
> To unsubscribe from this group, send email to
> [email protected]
>
> [ More Info ]
> For more options, visit this group at
> http://groups.google.com/group/Refresh-Austin
>
--
Larry Kubin
--
Our Web site: http://www.RefreshAustin.org/
You received this message because you are subscribed to the Google Groups
"Refresh Austin" group.
[ Posting ]
To post to this group, send email to [email protected]
Job-related postings should follow http://tr.im/refreshaustinjobspolicy
We do not accept job posts from recruiters.
[ Unsubscribe ]
To unsubscribe from this group, send email to
[email protected]
[ More Info ]
For more options, visit this group at
http://groups.google.com/group/Refresh-Austin