Stripping quotes out of a comma delimited file?

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2006
GregoryD
 
Posts: n/a
Default Stripping quotes out of a comma delimited file?

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


Reply With Quote
  #2 (permalink)  
Old 04-18-2006
Dana Cartwright
 
Posts: n/a
Default Re: Stripping quotes out of a comma delimited file?

"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


Reply With Quote
  #3 (permalink)  
Old 04-18-2006
Jerry Stuckle
 
Posts: n/a
Default Re: Stripping quotes out of a comma delimited file?

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
==================
Reply With Quote
  #4 (permalink)  
Old 04-18-2006
Jerry Stuckle
 
Posts: n/a
Default Re: Stripping quotes out of a comma delimited file?

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
==================
Reply With Quote
  #5 (permalink)  
Old 04-18-2006
tony@tony.com
 
Posts: n/a
Default Re: Stripping quotes out of a comma delimited file?

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
Reply With Quote
  #6 (permalink)  
Old 04-18-2006
Mladen Gogala
 
Posts: n/a
Default Re: Stripping quotes out of a comma delimited file?

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

Reply With Quote
  #7 (permalink)  
Old 04-20-2006
j_macaroni@yahoo.com
 
Posts: n/a
Default Re: Stripping quotes out of a comma delimited file?

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,...)]

Reply With Quote
  #8 (permalink)  
Old 04-20-2006
j_macaroni@yahoo.com
 
Posts: n/a
Default Re: Stripping quotes out of a comma delimited file?

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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:08 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0