anorakgirl
Programmer
Hi,
I have some code which takes a query and outputs the results in tab delimited format, which i require for an import into a different program. However, one of the fields is quite a bit description field (up to 4000 chars). When i do the download, some of the really long lines are wrapped onto a second line, which messes up the import. I'm not sure if it is php or apache which would automatically wrap lines at a certain number of characters, and if there is any thing I can do about it? It is not my code which is wrapping lines, and I have removed all line breaks from the field data.
Thanks!
Tamsin
~ ~
I have some code which takes a query and outputs the results in tab delimited format, which i require for an import into a different program. However, one of the fields is quite a bit description field (up to 4000 chars). When i do the download, some of the really long lines are wrapped onto a second line, which messes up the import. I'm not sure if it is php or apache which would automatically wrap lines at a certain number of characters, and if there is any thing I can do about it? It is not my code which is wrapping lines, and I have removed all line breaks from the field data.
Thanks!
Tamsin
Code:
function create_csv_file($info, $sql, $db)
{
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=$info.txt");
$result = pg_query($db, $sql);
$num = pg_num_rows($result);
//output the header row
$r = pg_fetch_row($result, 0);
for ($j=0; $j < count($r); $j++)
{
$f = pg_field_name($result, $j);
echo "$f\t";
}
echo "\r\n";
//output the first row
for ($j=0; $j < count($r); $j++)
{
echo "".output_field($r[$j])."\t";
}
echo "\r\n";
//output the rest of the rows
for($i=1; $i < $num; $i++)
{
$r = pg_fetch_row($result, $i);
for ($j=0; $j < count($r); $j++)
{
echo "".output_field($r[$j])."\t";
}
echo "\r\n";
}
}
function output_field($value) {
$strret = str_replace(array("\n","\r","\r\n","\t"),array(" "," "," "," "),strip_tags($value));
return $strret;
}
~ ~