By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,348 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,348 IT Pros & Developers. It's quick & easy.

Why do I get doc declaration in my csv file?

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Jan Nordgreen" <ro*******@hotmail.com> wrote in message
news:34*************************@posting.google.co m...
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?


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

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.