[thelist] Ereg

John Hicks johnlist at gulfbridge.net
Wed May 17 17:23:05 CDT 2006


Matt Warden wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Chris Price wrote:
>> I am uploading a csv file to the server and then exploding it in php to give
>> me data in arrays.
>>
>> When an entry in the csv file has a comma in it, that entry is surrounded by
>> double quotes which helps to differentiate a textual comma from a delimiting
>> comma.
>>
>> I want to escape the textual commas and delete the quotes before exploding
>> the strings into arrays.
>>
>> I figured I could find the occurrences of "foo,foo" using ereg and replace
>> them with foo,foo but I'm not sure how I should do that or if there is a
>> much simpler solution anyway.
> 
> 
> Something like (for simplicity i'll assume you're just converting it
> commas to \,):
> 
> $subject = 'HI, my name is, "Warden, Matt"';
> $foo = preg_replace('/"([^",\]*),([^",]*)"/', '"${1}\,${2}"', $subject);
> 

But that only transforms quoted strings containing only one comma.

What about quoted strings containing more than one comma?

--J



More information about the thelist mailing list