Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP Creation of CSV file

Posted on 2007-10-18
13
Medium Priority
?
2,474 Views
Last Modified: 2010-05-18
Hi

We are using php to create a csv file and then automatically ftp to a server for processing (its a selection of products for using with the google service froogle)

We are a bit stuck because we cant get it working properly.

After creating the file the script uploads the file ok but google cant process it properly, if we then download the file that it creates open it in excel save it over the exisitng file (without making any changes ) and then use the script (minus the file creation) to upload new file it works.

Are we missing a step in the creation of our csv file using php that excel cover when we open and save the csv file it does.

Any sugestins woud be much aprciated.
-s-
0
Comment
Question by:socross
  • 7
  • 4
12 Comments
 
LVL 8

Expert Comment

by:Mikkk
ID: 20105324
This is because froogle expects not a CSV but a XLS format, and when you save the file in excel it is saved in binary excel mode (maybe in csv extension but xls format)

check differences between created file and saved-by-excel file.
0
 
LVL 1

Author Comment

by:socross
ID: 20105349
ok  I had a look over the files butcould not see the obvious differnence, although there was less charaters in th froogle compatible one!

Can you advise what i need to do with the php file generation to create the correct format file for froogle???

Or what these differences are??

Thanks for such a quick reply

-s-
0
 
LVL 8

Expert Comment

by:Mikkk
ID: 20105438
As I've been reading, froogle acceps 'tab-delimited' file formats.
You need to create your csv file with the TABULATOR char as separation between fields.
If it does not work, can you paste 2 o 3 firsts lines of your created csv and the excel created one?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:Mikkk
ID: 20105443
For information on froogle file format: http://base.google.com/support/bin/answer.py?answer=59461&hl=en
0
 
LVL 1

Author Comment

by:socross
ID: 20105452
OK I need to stop working now but will test it in the morning

What is the TABULATORE Char and what do i use to insert it??? (basically what is the code for it???


Thanks for all your help so far???

-s-
0
 
LVL 8

Expert Comment

by:Mikkk
ID: 20105484
TABULATOR is the "TAB" key on the left of the keyboard.
is the ASCII char(9).
this is as comma separated field file: (csv)
sdfe,3r5wdf,32rwdf,34t2
this is as tab separated field file: (csv)
sdfe        3r5wdf      32rwdf      34t2
0
 
LVL 1

Author Comment

by:socross
ID: 20105498
of but if i am creaing this file in php i am currently using this method for tab

Coluumnhead\tnextcolum\tnextcol\t

So i am using the \t for the tab, What do i need to use to create the excel compatible version.

-s-
0
 
LVL 8

Expert Comment

by:Mikkk
ID: 20105576
Ok, you are using the right format then.
What char do you use for the end of line? \n ? \r ? ...
0
 
LVL 8

Expert Comment

by:Mikkk
ID: 20105583
Some other considerations:
# The file must be tab-delimited plain text.
# The first line of the file is the header -- it must contain attribute names, separated by tabs.
# One item per line; separate each attribute in that line by a tab.
# Do not include trailing tabs at the end of lines.
# Do not include tabs or line breaks in the attributes themselves
0
 
LVL 1

Author Comment

by:socross
ID: 20105605
Ok i have left the scripts on my mac at work, i wil check over all your sugestions, are the things you mentioned the sort of things that you can miss in the php file creation bu that opening in excel would fix???
0
 
LVL 8

Accepted Solution

by:
Mikkk earned 2000 total points
ID: 20105677
I think excel could change the end-of-line char, add some header, delete unnecessary tabs at end-of-line, etc...
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20305418
Force accepted.
Computer101
EE Admin
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question