Forum Moderators: coopster

Message Too Old, No Replies

Text file generating errant whitespace

Script is adding whitespace at top of output

         

jef79m

12:40 am on Dec 4, 2008 (gmt 0)

10+ Year Member



I have a small script to return a formatted text file to be used by another program, the problem is, the output has a few lines of whitespace at the top, it looks like 6 tabs. I'm not sure where they are coming from. Any ideas?

the config.php and opendb.php only set variables and create a db object, they have no output.

The php script:


<?php
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=\"membertable.txt\";" );

include 'lib/config.php';
include 'lib/opendb.php';

echo '"Member_Salutation","Member_Firstname","Member_Surname",Member_Number,' .
'"Member_Address1","Member_Address2","Member_Address3"';
echo "\r\n";

$query = 'SELECT Salutation, Firstname, Surname, Number, Address1, Address2, Address3 FROM members join membertypes on members.Membership_Type = membertypes.id where in_draw = 1';

$result = $db->query($query);
$text = "";
while ($row = $result->fetch_object())
{
for ($i = 0; $i < $db->field_count; $i++)
{
if (current($row)) {
$text = $text.'"'.current($row).'",';
} else {
$text = $text.'"",';
}
next($row);
}

echo rtrim($text,",")."\r\n";
$text = "";
}
include 'lib/closedb.php';
?>

The output file:

"Member_Salutation","Member_Firstname","Member_Surname",Member_Number,"Member_Address1","Member_Address2","Member_Address3"
"Mr","Peter","Lochrin","3589","#*$!#*$!xDrive","Ashtonfield",""
"Mrs","Louise","Lochrin","3590","#*$!XDrive","Ashtonfield",""
"Mr","Darren","Brew","3591","7 #*$!xx","Thornton",""
"Mrs","Melissa","Brew","3592","7 #*$!xx","Thornton",""
"Ms","Sue","Johnson","3593","#*$!xClose","Ashtonfield",""
"Ms","Leisha","Collett","3594","#*$!xAvenue","Berkeley Vale",""

jef79m

1:36 am on Dec 4, 2008 (gmt 0)

10+ Year Member



So dumb. I worked it out.
One of my includes had some empty lines after the closing php tag.

thanks anyway.

eelixduppy

2:33 am on Dec 4, 2008 (gmt 0)



cool, glad you got the issue resolved. and Welcome to WebmasterWorld! :)