Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 06:42 AM
Jan Nordgreen
Guest
 
Posts: n/a
Default Why do I get doc declaration in my csv file?

In my main.php I have this doc declaration at the top:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Later in main.php I use code from excel.php

case 'Export to Excel':
require 'excel.php';
break;

This is excel.php:

<?php

// export to csv file the table bmbookmark and call it bookmarks.csv
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=bookmarks.csv");
$result = mysql_query("
SELECT bmcat.title, bmbookmark.title, bmbookmark.url,
bmbookmark.order,
bmbookmark.comment, bmbookmark.private, bmbookmark.hot
FROM bmbookmark
JOIN bmcat on bmbookmark.cat_id = bmcat.id
ORDER BY bmcat.title, bmbookmark.title
");
while($row = mysql_fetch_row($result)){
print implode(",", $row)."\n";
};
mysql_free_result($result);
exit();

?>

When I export to Excel, the csv file that is created has at the top:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

I have to manually remove this doc declaration for the csv file to
behave the way it should.

What am I doing wrong? Why is this doc declaration printed in the csv
file?

Regards,
Jan Nordgreen

---

My diary:
http://jansdiary.simpler-solutions.net

Seductive math problems for the modern mind:
http://thinkagain.simpler-solutions.net

Tools for better schools:
http://moderntimes.simpler-solutions.net

What I read:
http://www.bloglines.com/public/damezumari

Mathematical ulterior motives:
http://mumnet.tripod.com
  #2  
Old July 17th, 2005, 06:42 AM
Tony Marston
Guest
 
Posts: n/a
Default Re: Why do I get doc declaration in my csv file?


"Jan Nordgreen" <room23111@hotmail.com> wrote in message
news:3488b88c.0406081416.7114716@posting.google.co m...[color=blue]
> In my main.php I have this doc declaration at the top:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>
> Later in main.php I use code from excel.php
>
> case 'Export to Excel':
> require 'excel.php';
> break;
>
> This is excel.php:
>
> <?php
>
> // export to csv file the table bmbookmark and call it bookmarks.csv
> header("Content-type: text/csv");
> header("Content-Disposition: attachment; filename=bookmarks.csv");
> $result = mysql_query("
> SELECT bmcat.title, bmbookmark.title, bmbookmark.url,
> bmbookmark.order,
> bmbookmark.comment, bmbookmark.private, bmbookmark.hot
> FROM bmbookmark
> JOIN bmcat on bmbookmark.cat_id = bmcat.id
> ORDER BY bmcat.title, bmbookmark.title
> ");
> while($row = mysql_fetch_row($result)){
> print implode(",", $row)."\n";
> };
> mysql_free_result($result);
> exit();
>
> ?>
>
> When I export to Excel, the csv file that is created has at the top:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>
> I have to manually remove this doc declaration for the csv file to
> behave the way it should.
>
> What am I doing wrong? Why is this doc declaration printed in the csv
> file?[/color]

Because you have it in main.php just before the place where you have require
'excel.php';

This is not within <?php ... ?> tags (otherwise you would get an error)
therefore it is passed straight to the output file without any form of
processing. If you don't want this appearing in your output then simply
remove it from the source code.

What is that DOCTYPE declaration for anyway? It has nothing to do with PHP.

--
Tony Marston

http://www.tonymarston.net



 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles