473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Apr 17 '06 #1
7 1969
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.
js*******@attglobal.net
==================
Apr 18 '06 #2
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:h7******************************@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
Apr 18 '06 #3
Dana Cartwright wrote:
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:h7******************************@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.
js*******@attglobal.net
==================
Apr 18 '06 #4
In article <nZ******************************@comcast.com>,
js*******@attglobal.net says...
Dana Cartwright wrote:
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:h7******************************@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
Apr 18 '06 #5
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

Apr 18 '06 #6
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,...)]

Apr 20 '06 #7
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


Apr 20 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: David | last post by:
Hi, I'm trying to pass a querystring with certain common words removed (and, the, if, of etc). The code below replaces the keywords with "" or whatever I choose, but what I'd like to do is...
3
by: Elmo Watson | last post by:
I've been asked to develop a semi-automated type situation where we have a database table (sql server) and periodically, there will be a comma delimited file from which we need to import the data,...
1
by: John B. Lorenz | last post by:
I'm attempting to write an input routine that reads from a comma delimited file. I need to read in one record at a time, assign each field to a field array and then continue with my normal...
9
by: Bernie Yaeger | last post by:
Is there a way to convert or copy a .xml file to a comma delimited text file using vb .net? Thanks for any help. Bernie Yaeger
0
by: Masa Ito | last post by:
I have pipe delimited (and comma/tab) files that I read with JET using a schema file. Occasionally a field has multiple quotes (") inside a single field - which chokes the line (the rest of the...
4
by: JustSomeGuy | last post by:
Hi. I have a comma delimited text file that I want to parse. I was going to use fscanf from the C library but as my app is written in C++ I thought I'd use the std io stream library... My Text...
5
by: bebe | last post by:
Hi, How do I write a function in SQL to convert data from a table to a comma delimited text file and get it imported in excel or word? I already have a function that convers data to an xml. but I...
1
by: Al G | last post by:
Hi, I am reading a CSV file with the code below. When I run into a " (quote mark) in the file, I get a "malformed line" exception. Can anyone point me to a way to handle this? Thanks in...
0
by: Kristi | last post by:
I need to create a CL program that will take a PF, and create a tab delimited file that has comma seperated column headings as the first record. I know i can use cpytostmf/cpytoimpf to create the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.