Stripping quotes out of a comma delimited file?
Stripping quotes out of a comma delimited file?
am 18.04.2006 01:27:08 von GregoryD
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
Re: Stripping quotes out of a comma delimited file?
am 18.04.2006 02:58:06 von Dana Cartwright
"Jerry Stuckle" 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
Re: Stripping quotes out of a comma delimited file?
am 18.04.2006 03:16:43 von Jerry Stuckle
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
==================
Re: Stripping quotes out of a comma delimited file?
am 18.04.2006 04:22:28 von Jerry Stuckle
Dana Cartwright wrote:
> "Jerry Stuckle" 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
==================
Re: Stripping quotes out of a comma delimited file?
am 18.04.2006 10:34:59 von tony
In article ,
jstucklex@attglobal.net says...
> Dana Cartwright wrote:
> > "Jerry Stuckle" 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
Re: Stripping quotes out of a comma delimited file?
am 18.04.2006 14:32:46 von Mladen Gogala
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
Re: Stripping quotes out of a comma delimited file?
am 20.04.2006 04:38:49 von j_macaroni
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,...)]
Re: Stripping quotes out of a comma delimited file?
am 20.04.2006 04:52:58 von j_macaroni
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