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 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
==================
"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 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
==================
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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,...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |