producing a csv file with large text
Posted: Mon May 14, 2007 5:42 am
Hi I have a discussion forum on my site and I am trying to add a facility to create a csv file of all the forums threads.
I am using the following code:
}
the csv is created. But due to the amount of text in the body variable the body field is all over the csv file and messes up how the columsn are structured. I have stripped tags and slahes but this has not fixed the problem.
Is there a certain thing that needs to be done to fix this?
All suggestions welcome.
Thanks in advance
I am using the following code:
Code: Select all
function threads_csv()
{
db_connect();
$result = mysql_query("Select * from hrd order by thread_date DESC");
while($row = mysql_fetch_array($result))
{
$thread_id = $row['thread_id'];
$parent_id = $row['parent_id'];
$order = $row['thread_order'];
$title = $row['thread_title'];
$body = strip_tags($row['thread_body']);
$body = stripslashes($body);
$user = $row['thread_user'];
$date = $row['thread_date'];
$data .= "$thread_id, $parent_id, $order, $title, $user, $date, $body\n";
}
$filename = "training_journal_threads.csv";
header ('Content-type: text/csv');
header ('Content-Disposition: attachment; filename='.$filename);
print "Thread ID, Parent Thread, Order, Title,User, Date, Body\n";
echo $data;
exit();the csv is created. But due to the amount of text in the body variable the body field is all over the csv file and messes up how the columsn are structured. I have stripped tags and slahes but this has not fixed the problem.
Is there a certain thing that needs to be done to fix this?
All suggestions welcome.
Thanks in advance