Source code for:
formatfile.php
<HTML>
<HEAD>
<TITLE> Q7310 Working with Files; Report Generation</TITLE>
</HEAD>
<BODY bgcolor="#000000" text="yellow" link="#0000FF" vlink="#FF0000" alink="#00FF00">
<?php
// ============ prtBR FUNCTION =========================
FUNCTION prtBR($text){
PRINT ("$text <br> \n");
}
?>
<?php
/*
======== FORMAT & PRINT Cumulative Responses FILE ===================
FGETCSV - reads a line from a delimated file, default is "," ====================================================================
*/
$filename = "iac_rawdata.txt";
IF (FILE_EXISTS ($filename)) {
prtBR ("The file <b> $filename </b> exist.");
} ELSE {
prtBR ("<FONT color='red'> $filename does not exist </FONT>");
}
$fp = FOPEN( $filename, 'a' ) or DIE("Couldn't open $filename");
prtBR ("$filename is open");
?>
<?php
?>
<TABLE width="90%" border=1 align="center">
<TR>
<TD>
<FONT color="red">
<B> <CENTER>
RAW TEXT FILE SUBMISSIONS REPORT
</CENTER> </B>
</FONT>
</TD>
</TR>
<TR>
<TD>
<B> Explanation </B> <BR>
On the <B> first </B> line of a RECORD, it prints the number of FIELDS found in red. <BR>
This is a report from comma delimited file; FIELDS are defined by ",". <BR>
The report prints the browser information FIELD data on the <B> second</B> line. <BR>
On subsequent lines it prints data from FIELDS of each RECORD. <BR>
The <B> first line of the report </B> prints the FEILD names identified by $ prefix.<BR>
</TD>
</TR>
<TR>
<TD>
<?php
// =================== READ & PRINT Response.txt FILES ==========
$row = 1;
$fp = FOPEN ("response.txt", "r");
WHILE (($data = FGETCSV($fp, 1000, ",")) !== FALSE) {
$num = COUNT($data);
prtBR ("<FONT color='red'> $num fields in line $row: </FONT> \n");
$row++;
FOR($c=0; $c < $num; $c++) {
ECHO $data[$c] . "<br />\n";
}
}
FCLOSE($fp);
?>
</TD>
</TR>
</TABLE>
<HR>
<FONT face="Arial, Helvetica, sans-serif" size="-1">
Report Module Last Updated: <BR>
<!-- #BeginDate format:fcAm1a -->Wednesday, November 17, 2004 11:57 PM<!-- #EndDate -->
<BR>
Contact <A href="mailto:4ascii@marz.com">Web Developer</A>
</FONT>
</BODY>
</HTML>
|