bboundy Posted August 22, 2007 Share Posted August 22, 2007 I have a script that outputs data into a .tab file, but for some reason it adds lines before the first row of data, and after the last one. I was wondering if there was a special character (like "\t" for tab) for backspace or delete? Or can anyone else see a way of getting rid of the lines. I'm using a force download header, to make the browser download the contents of the page, rather than display them. Quote Link to comment https://forums.phpfreaks.com/topic/66090-placing-backspace-special-characters-in-script/ Share on other sites More sharing options...
keeB Posted August 22, 2007 Share Posted August 22, 2007 No. Basically, what you want to do is remove them before saving. Can you post your code so that it's easier to point out how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/66090-placing-backspace-special-characters-in-script/#findComment-330555 Share on other sites More sharing options...
Hypnos Posted August 22, 2007 Share Posted August 22, 2007 You could do something like this: <?php $handle = @fopen("/tmp/inputfile.txt", "r"); while ($buffer = fgets($handle)) { //skip blank lines if($buffer[0] == "\n" || $buffer[1] == "\n" ) { echo $buffer; } } That should skip all blank lines, as long as they don't have any spaces. Even though $buffer is a string, you can use it like a character array, just like C++. Quote Link to comment https://forums.phpfreaks.com/topic/66090-placing-backspace-special-characters-in-script/#findComment-330577 Share on other sites More sharing options...
bboundy Posted August 22, 2007 Author Share Posted August 22, 2007 I never really learned how to use the fopen commands. But here is my code: <?php //This section causes the page to download whatever it would normally display on screen. header("Content-Type: application/download"); header("Content-Disposition: attachment; filename=\"absentees.tab\""); //field names. Use these for debug and further changes. //echo "Absent Flag"."\t"."Absent for Periods"."\t"."Academic Year"."\t"."Arrival Time"."\t"."Date of Absence"."\t"."Departure Time"."\t"."Note Received"."\t"."Reason"."\t"."StudentID"."\t"."Type of Absence"."\n"; $sql = mysql_query("select replace(a.per,',','') as per, s.year, a.arrivetime, concat_ws(', ',upper(s.lname), s.fname) as name, date_format(from_unixtime(a.recabdate),'%d/%m/%Y') as date, date_format(from_unixtime(a.arrivetime),'%k:%i %p') as arrive, date_format(from_unixtime(a.departtime),'%k:%i %p') as depart, a.note, a.reason, lpad(s.id,6,'0') as id, a.type, t.init from teachers t, students s, absent a where a.tid = t.id and a.sid = s.id"); while ($row = mysql_fetch_array($sql)) { $date = $row["date"]; $name = $row["name"]; $teacher = $row["init"]; $per = $row["per"]; $year = $row["year"]; $arrive = $row["arrive"]; $depart = $row["depart"]; $note = $row["note"]; $reason = $row["reason"]; $sid = $row["id"]; $type = $row["type"]; if ($note == 0){ $note = ""; } echo "Absent"."\t"."$per"."\t"."$year"."\t"."$arrive"."\t"."$date"."\t"."$depart"."\t"."$note"."\t"."$reason"."\t"."$sid"."\t"."$type"."\n"; //echo "$date"."\t"."$name"."\t"."$teacher"."\t"."$per"."\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/66090-placing-backspace-special-characters-in-script/#findComment-330604 Share on other sites More sharing options...
bboundy Posted August 23, 2007 Author Share Posted August 23, 2007 Is it something to do with the mime types i'm using? Quote Link to comment https://forums.phpfreaks.com/topic/66090-placing-backspace-special-characters-in-script/#findComment-331460 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.