[Gllug] OT: Regular Expression Help Needed Please
Mike Leigh
MikeL at hornbill.com
Thu Oct 7 11:27:08 UTC 2004
Hi,
I am parsing a csv file and creating SQL insert or update statements and am
using the following regex to create an array of fields.
//remove commas from within quotation marks. e.g. from [this,",,i,s,,
a,",string] to [this,"is a",string]
preg_match("/\"[\d\D]*,+[\d\D]*\"/",$line, $matches)
The problem I have is wrapping of " marks around the fields.
this string >>> this,",,i,s,, a,",string
gets converted to this >>> this,"is a",string
which is what I would expect to hapen. I then explode the sting on , and
get the correct array elements
now heres the problem with it.
this string >>> this,",,i,s,, a,",string,"and this is, extra text at the
end"
gets converted to this >>> this,"is a"string"and this is extra text at the
end"
which is not what I want to happen as it mucks up my array elements.
Can anyone point me in the right direction.
Note I am using php 4.3 and the default fget_csv functions do not give methe
correct results which is why I had to use the above method. Incase your
curious as to what the data is its a Active Directory csv dump.
Help please :)
Mike
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list