Jump to content

Placing backspace special characters in script


bboundy

Recommended Posts

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.

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++.

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";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.