Click to See Complete Forum and Search --> : Trying to create html pages using file names of pdfs for use on CD


XiMiX
11-01-2006, 12:49 PM
Here is my code... all of the //---TESTs work except for the very last echo all i get is a blank page and no files show up in the folder... bare in mind i hate using PHP in an OOP way.
--------------------------------------------------------
<?php

$file = "xml.txt";
$fp = fopen($file, "r");
$filesize = filesize($file);
$data = fread($fp, $filesize);
$fc = fclose($fp);
// --- TEST: if($data){echo "File read successfully!";}else{echo "failed to read file!";}

///--- explode the database by rows using the new line character
$rows = explode("\n", $data);
///--- TEST: $i = 0; while($rows[$i]){ echo substr($rows[$i], 13)."<br />\n"; $i++;}

$i = 0;
while($rows[$i]){ $pieces[$i] = explode("\"", $rows[$i]); $i++;}
///--- TEST: $i = 0; $a = 50; while($pieces[$a][$i]){ echo "The value of \$pieces[".$a."][".$i."] is: ".$pieces[$a][$i]."<br />\n"; $i++;}

$ii = 0;
while($rows[$i]){
if(substr_count($pieces[$i][9], ".pdf")){
$pdfname = substr($pieces[$i][9], 52, -14);
$name[$ii] = substr($pdfname, 0, -4);
$title[$ii] = $pieces[$i][7];
///--- TEST: echo $title[$ii].": ".$name[$ii]."<br />\n";$ii++;
}else{

}
$i++;
}

$i = 0;
$ii = 0;
while($name[$ii]){
$header ="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n";
$header .="<HTML>\n";
$header .="<HEAD>\n";
$header .="<TITLE>".$title[$ii]."</TITLE>\n";
$header .="</HEAD>\n";
$header .="<BODY>\n";

$footer ="</BODY>\n";
$footer .="</HTML>";

$filenum = substr($name[$ii], 4, 2);

$anchor[$ii] = "<img src =\"ld".$filenum."_1.gif\" border=\"0\"><br />\n";
$anchor[$ii] .= "<h3>".$title[$ii]."</h3><br />\n";
$anchor[$ii] .= "Click here to open <a href=\"".$name[$ii].".pdf\" target\"_blank\">".$title[$ii]."</a>\n";

echo $anchor[$ii]."<br />";

$file = "htms/".$name[$ii]."html";
$fw = fopen($file, "w");
fwrite($fw, $header);
fwrite($fw, $anchor[$ii]);
fwrite($fw, $footer);
fclose($fw);
$i++;
$ii++;

}

?>