469,267 Members | 860 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

Export to csv

Hi all,

I'm trying to generate a csv file from an ldap query (by generating a
string by concatenating with comma's - echo of the string in the browser
looks fine).
Is there a simple way (without using dedicated classes) to export this
string to a csv file (or display the csv in the browser, so it can be saved?

Thanks a lot!

Zeff.
Oct 5 '05 #1
8 28351

Zeff wrote:
Hi all,

I'm trying to generate a csv file from an ldap query (by generating a
string by concatenating with comma's - echo of the string in the browser
looks fine).
Is there a simple way (without using dedicated classes) to export this
string to a csv file (or display the csv in the browser, so it can be saved?

Thanks a lot!

Zeff.

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=YOUR_FILE.csv");

print $YOUR_STRING;

micha

Oct 5 '05 #2
Hi Micha,

Thanks for your suggestion. I checked out this option before, but I get
an error message.
"Warning: Cannot modify header information - headers already sent by
(output started at /var/www/myfile.php:4) in /var/www/myfile.php on line
208"

Should I edit my php.ini?

Zeff
___
chotiwallah wrote:
Zeff wrote:
Hi all,

I'm trying to generate a csv file from an ldap query (by generating a
string by concatenating with comma's - echo of the string in the browser
looks fine).
Is there a simple way (without using dedicated classes) to export this
string to a csv file (or display the csv in the browser, so it can be saved?

Thanks a lot!

Zeff.


header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=YOUR_FILE.csv");

print $YOUR_STRING;

micha

Oct 5 '05 #3
You don't need to edit your php.ini, it wont help.
You can send only one header per session. Try to handle the problem in
another php file, and send only following headers:

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=YOUR_FILE.csv");

/* generating csv files comes here */

hope it helps.

Zeff wrote:
Hi Micha,

Thanks for your suggestion. I checked out this option before, but I get
an error message.
"Warning: Cannot modify header information - headers already sent by
(output started at /var/www/myfile.php:4) in /var/www/myfile.php on line
208"

Should I edit my php.ini?

Zeff
___
chotiwallah wrote:
Zeff wrote:
Hi all,

I'm trying to generate a csv file from an ldap query (by generating a
string by concatenating with comma's - echo of the string in the browser
looks fine).
Is there a simple way (without using dedicated classes) to export this
string to a csv file (or display the csv in the browser, so it can be saved?

Thanks a lot!

Zeff.


header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=YOUR_FILE.csv");

print $YOUR_STRING;

micha


Oct 5 '05 #4

Zeff wrote:
Hi Micha,

Thanks for your suggestion. I checked out this option before, but I get
an error message.
"Warning: Cannot modify header information - headers already sent by
(output started at /var/www/myfile.php:4) in /var/www/myfile.php on line
208"

Should I edit my php.ini?

Zeff
___


well yes, only one header allowed per script.

your error is produced by sending output to the browser before you send
the header. send the headers 1st thing or buffer the output.

in your special case i would make sure that no output except the csv
data is sent, so this data is not messed up in some way.

micha

Oct 5 '05 #5
Thanks folks,

with your help, problem was solved!

Zeff

chotiwallah wrote:
Zeff wrote:
Hi Micha,

Thanks for your suggestion. I checked out this option before, but I get
an error message.
"Warning: Cannot modify header information - headers already sent by
(output started at /var/www/myfile.php:4) in /var/www/myfile.php on line
208"

Should I edit my php.ini?

Zeff
___

well yes, only one header allowed per script.

your error is produced by sending output to the browser before you send
the header. send the headers 1st thing or buffer the output.

in your special case i would make sure that no output except the csv
data is sent, so this data is not messed up in some way.

micha

Oct 6 '05 #6
chotiwallah wrote:
Zeff wrote: <snip>
header("Content-type: text/plain");


IIRC, the correct Content-type for CSV is "text/x-csv".
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Oct 6 '05 #7
R. Rajesh Jeba Anbiah wrote:
chotiwallah wrote:
header("Content-type: text/plain");


IIRC, the correct Content-type for CSV is "text/x-csv".


I was going to make a similar remark but you beat me to it.

text/x-csv is common, for sure, but it isn't and can't be registered, it
being a 'private' type (indicated by the 'x-' prefix). I would say
text/x-csv is more useful at the moment in that the likelihood of its
being interpreted as signifying CSV is greater (at least in my browser).

I don't know how far text/plain is meant to stretch: at what stage do
things start becoming 'formatting commands or directives' (the wording of
RFC2046)? does this very post - the one you're reading - not contain
'formatting commands' in the shape of those quote markers >'s?

text/x-csv would be my choice too though.

[why does TSV have a registered type but not CSV?]

how you doin?

--
Jock
Oct 7 '05 #8
John Dunlop wrote:
R. Rajesh Jeba Anbiah wrote:
chotiwallah wrote:
header("Content-type: text/plain"); IIRC, the correct Content-type for CSV is "text/x-csv".

<snip> I don't know how far text/plain is meant to stretch: at what stage do
things start becoming 'formatting commands or directives' (the wording of
RFC2046)? does this very post - the one you're reading - not contain
'formatting commands' in the shape of those quote markers >'s?

text/x-csv would be my choice too though.


Hmmm... Sometimes I used to wonder, if John Dunlop is a real
humanbeing or a RFC bot:-) LOL.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Oct 11 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by DarkSpy | last post: by
205 posts views Thread by Jeremy Siek | last post: by
1 post views Thread by Do Park via SQLMonster.com | last post: by
6 posts views Thread by maricel | last post: by
5 posts views Thread by David | last post: by
1 post views Thread by chaitu | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.