FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Send .csv file to browser
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Send .csv file to browser [message #170014 is a reply to message #170005] Tue, 05 October 2010 16:05 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 10/5/2010 10:55 AM, sheldonlg wrote:
> On 10/5/2010 10:20 AM, Derek Turner wrote:
>> On Tue, 05 Oct 2010 14:19:04 +0000, Derek Turner wrote:
>>
>>
>>>
>>> 3. Use appropriate header files and then readfile()
>>
>> Sorry lines/statements
>
> Why not simply
>
> $theData = getDataFromTableAsArrayOfNonAssociativeArrays();
> foreach ($theData as $rec) {
> $line = implode(',', $rec);
> print $line . '<br>';
> }
>
> The user can then cut and paste it into a file or you can put in code
> for the user to download that piece.
>
> Another approach is to output an Excel file and the user can then output
> from that Excel file to a .csv file.
>
>

Right idea, but some problems. First of all, what happens if a field
contains a comma i.e. "Smith, Jr.". Text fields also need to be
surrounded by double quotes, and any double quotes in the text field
must be doubled to be a valid CSV file. Also, some places use a

Not hard - just a matter of looking at each field, and if it is numeric,
insert it in the stream. If it is text, replace all occurrences of '"'
with '""' and insert it with surrounding quotes. Of course, use commas
to separate the fields.

Then just output directly with the appropriate headers.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: file access permission?
Next Topic: Process queue without cron jobs
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 12:26:01 GMT 2024

Total time taken to generate the page: 0.03598 seconds