Connecting Tech Pros Worldwide Forums | Help | Site Map

Why do I get doc declaration in my csv file?

Jan Nordgreen
Guest
 
Posts: n/a
#1: Jul 17 '05
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

Tony Marston
Guest
 
Posts: n/a
#2: Jul 17 '05

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



Closed Thread