PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue May 23, 2017 5:37 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Aug 21, 2014 8:11 am 
Offline
Forum Newbie

Joined: Thu May 29, 2014 12:15 am
Posts: 4
Is there any way to put commas in csv file.

I've got a two column CSV with a name and a number. Some people's name use commas, for example "Joe Blow, CFA." This comma breaks the entire CSV format.
How to handle this type of cases?Any alternative is there? Please let me know.


Top
 Profile  
 
PostPosted: Thu Aug 21, 2014 8:19 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6243
Location: Montreal, Canada
Moved because this has nothing to do with Linux.

Wrapping your columns in quotes should prevent problems caused by commas in your values. You could also use a different separator.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Fri Aug 22, 2014 10:24 am 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6444
Location: 53.01N x 112.48W
Re: escaping: The standardized practice is to escape double quotes with double-double quotes:

42,"Joe ""The Blowman"" Blow, CFA.",100.0

http://www.ietf.org/rfc/rfc4180.txt, search for "double quotes"

_________________
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.


Top
 Profile  
 
PostPosted: Fri Aug 22, 2014 12:31 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6418
Location: WA, USA
If you're writing the CSV using PHP then use fputcsv, which will deal with the quote thing for you.


Top
 Profile  
 
PostPosted: Fri Aug 29, 2014 8:07 am 
Offline
Forum Commoner

Joined: Thu Oct 10, 2013 8:40 am
Posts: 26
Location: Manchester
I am not sure if there is any way to use commas in a csv file.

_________________
Tayla the great


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group