This is a discussion on Stripping quotes out of a comma delimited file? within the PHP Language forums, part of the PHP Programming Forums category; I have a flat file that I'm trying to stick into a MySQL database. One record per line, multiple ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a flat file that I'm trying to stick into a MySQL database. One
record per line, multiple fields per record, and many of them are null fields which are just double quotes without a space between. It's probably nothing really major for people who have done this before, but I'm a bit stumped. The file is comma delimited. Every field is surrounded by double quotes. I've done quite a bit of searching, on the php site and elsewhere, but I can't seem to get it to strip the quotes out so I can explode the file line by line to grab the fields. Anyone have a quick solution? GregoryD |
|
|||
|
"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:h7OdnZi9PcG-rdnZnZ2dnUVZ_tidnZ2d@comcast.com... > Sounds like a .csv file. Check out fgetcsv(). Jerry, Jerry, you have made me *so* unhappy. I spent the weekend writing a parser for a .csv file. Never crossed my mind to look for one built in to PHP. Sigh. You couldn't have posted this last week? -Dana |
|
|||
|
GregoryD wrote:
> I have a flat file that I'm trying to stick into a MySQL database. One > record per line, multiple fields per record, and many of them are null > fields which are just double quotes without a space between. It's probably > nothing really major for people who have done this before, but I'm a bit > stumped. The file is comma delimited. Every field is surrounded by double > quotes. I've done quite a bit of searching, on the php site and elsewhere, > but I can't seem to get it to strip the quotes out so I can explode the file > line by line to grab the fields. Anyone have a quick solution? > > GregoryD > > Sounds like a .csv file. Check out fgetcsv(). -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Dana Cartwright wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message > news:h7OdnZi9PcG-rdnZnZ2dnUVZ_tidnZ2d@comcast.com... > > >>Sounds like a .csv file. Check out fgetcsv(). > > > Jerry, Jerry, you have made me *so* unhappy. I spent the weekend writing a > parser for a .csv file. Never crossed my mind to look for one built in to > PHP. Sigh. You couldn't have posted this last week? > > -Dana > > Dana, You didn't ask last week! :-) -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
In article <nZWdnQAAVZQbotnZnZ2dnUVZ_u-dnZ2d@comcast.com>,
jstucklex@attglobal.net says... > Dana Cartwright wrote: > > "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message > > news:h7OdnZi9PcG-rdnZnZ2dnUVZ_tidnZ2d@comcast.com... > > > > > >>Sounds like a .csv file. Check out fgetcsv(). > > > > > > Jerry, Jerry, you have made me *so* unhappy. I spent the weekend writing a > > parser for a .csv file. Never crossed my mind to look for one built in to > > PHP. Sigh. You couldn't have posted this last week? > > > > -Dana > > > > > > Dana, > Dana I guess thats one benefit to being new to a language as I am - you HAVE to keep looking through the docs to do anything at all... As a big csv fanatic I was delighted to find this ;-) On the other hand - a week to do a parse csv? Is there no way to do something with sed ? exec(sed params); or something like that. Its just a thought I dont know how practical. tony |
|
|||
|
On Mon, 17 Apr 2006 18:27:08 -0500, GregoryD wrote:
> I have a flat file that I'm trying to stick into a MySQL database. One > record per line, multiple fields per record, and many of them are null > fields which are just double quotes without a space between. It's probably > nothing really major for people who have done this before, but I'm a bit > stumped. The file is comma delimited. Every field is surrounded by double > quotes. I've done quite a bit of searching, on the php site and elsewhere, > but I can't seem to get it to strip the quotes out so I can explode the file > line by line to grab the fields. Anyone have a quick solution? > > GregoryD Sounds like something for preg_match with a patern like '/"(.*)",?/'. You will have to repeat it until you exhaust the input string. -- http://www.mgogala.com |
|
|||
|
Check out this MMySQL command. Its designed to handle this.
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name' [REPLACE | IGNORE] INTO TABLE tbl_name [FIELDS [TERMINATED BY 'string'] [[OPTIONALLY] ENCLOSED BY 'char'] [ESCAPED BY 'char'] ] [LINES [STARTING BY 'string'] [TERMINATED BY 'string'] ] [IGNORE number LINES] [(col_name_or_user_var,...)] [SET col_name = expr,...)] |
|
|||
|
I didnt try this but its someones example in the online docs file.
LOAD DATA INFILE "filename.csv" INTO TABLE your_table FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED BY "\\r\\n"; GregoryD wrote: > I have a flat file that I'm trying to stick into a MySQL database. One > record per line, multiple fields per record, and many of them are null > fields which are just double quotes without a space between. It's probably > nothing really major for people who have done this before, but I'm a bit > stumped. The file is comma delimited. Every field is surrounded by double > quotes. I've done quite a bit of searching, on the php site and elsewhere, > but I can't seem to get it to strip the quotes out so I can explode the file > line by line to grab the fields. Anyone have a quick solution? > > GregoryD |