10, January 2009

Generating a .csv file in PHP - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Generating a .csv file in PHP
« previous next »
Pages: [1] Print

Author Topic: Generating a .csv file in PHP  (Read 716 times)
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« on: Feb 20, 2006, 06:04:19 PM »

This is a simple question really...

When generating a .csv file in php, how do you escape commas in sentences or fields. For example, If I want to put Region, Country into one field, how do I stop the csv file from spliting it into two cells? I have tried double and single quotes without any luck.

Thanks


Last blog : Site of the Month - August 2007
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8363
43165 credits
Members referred : 3



« Reply #1 on: Feb 20, 2006, 06:13:34 PM »

You should put it like this :

Code:
"Region, Country"

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #2 on: Feb 20, 2006, 06:20:22 PM »

I have tried that, but it doesn't work...

Also, if I have a paragraph of text, I want to all be in one cell and not spread out over the spreadsheet.


Last blog : Site of the Month - August 2007
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8363
43165 credits
Members referred : 3



« Reply #3 on: Feb 20, 2006, 06:23:12 PM »

Maybe the import program has some kind of bug?

Check this : http://www.ietf.org/rfc/rfc4180.txt Visit through proxy

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8363
43165 credits
Members referred : 3



« Reply #4 on: Feb 20, 2006, 06:24:46 PM »

Also you can use from mysql the "SELECT INTO OUTFILE" command

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #5 on: Feb 20, 2006, 06:34:43 PM »

Ah, this is what I worked out so far...

There must be no spaces after the commas. For example...

This one is incorrect!
Code:
fwrite ($fd, "$row->data, \"$row->WineryName, $row->CountryName\", $row->BlendName\n");

This one is correct!
Code:
fwrite ($fd, "$row->data,\"$row->WineryName, $row->CountryName\",$row->BlendName\n");


Last blog : Site of the Month - August 2007
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #6 on: Feb 20, 2006, 06:36:21 PM »

Thanks for the help Nick!


Last blog : Site of the Month - August 2007
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8363
43165 credits
Members referred : 3



« Reply #7 on: Feb 20, 2006, 06:45:03 PM »

Ha.

At least we learned something today. right? (I know this phrase sounds familliar....)

Quote
Thanks for the help Nick!

You are welcome Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1523
6847 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #8 on: Feb 20, 2006, 06:46:05 PM »

Yes, it is becoming a trend to learn something everyday! LOL

Cool


Last blog : Site of the Month - August 2007
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #9 on: Feb 23, 2006, 12:52:54 PM »

The .csv files I create look like this:

="alpha data , comma's can be used without a problem";123;34;="more text"

be sure to have your list sepperator in 'regional settings' set to ;


Last blog : Are You Stumbling Yet?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8363
43165 credits
Members referred : 3



« Reply #10 on: Feb 23, 2006, 12:56:01 PM »

Even this way you should use "" when you are inserting the ; character.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8363
43165 credits
Members referred : 3



« Reply #11 on: Feb 24, 2006, 02:44:26 PM »

What about reading CSV files?

Is there any cool class/functions that you use for?

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy or twitter Visit through proxy

Last blog : Monetizing Old Posts
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=1558
Tags : php mysql Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: Generating a .csv file in PHP
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jan 10, 2009, 03:37:32 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 38.670
Total Topics: 7.775
Total Members: 4.665
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: mosesbradford

28 Guests, 5 Users online :

15 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2009 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.