If an element of an array returned by file() is a blank line, then it will be equal to "\n", "\r" or "\r\n", depending on your platform (usually \n will do).
I finally found that "\r\n" was the correct end of line sequence. The trouble however, is that even if I rtrim() the line, I still need to use this as the indicator. Does that mean that rtrim() isn't properly removing them or am I missing something? I don't know but I'm up and running so for now that's water under the bridge.
Just to summarize what I ended up with
$page = array();
$file = 'fleet.tdb';
$data = file($file) or die('Could not read file!');
$blk = array();
function getNextDataBlockEndIndex() {
global $data;
$stopmark = "\r\n";
$i = -1;
do {
if (++$i < count($data)) $line = $data[$i];
//rtrim($line); // makes no difference
} while (($i < count($data)) AND (!(strcmp($line, $stopmark) == 0)));
return $i;
}
function getNextDataBlock() {
global $blk;
global $data;
$idx = getNextDataBlockEndIndex();
$blk = array_slice($data, 0, $idx);
reset($data);
$data = array_slice($data, $idx+1);
}
function getNextPlaneBlock() {
global $blk;
getNextDataBlock();
if (! empty($blk)) {
echo "<div class=\"ad_note\">";
echo "<div class=\"fleet_tn\"><a target=\"pic_view\" href=\"images/fleet/$blk[1]\">
<img src=\"images/fleet/$blk[2]\" border=\"0\" alt=\"thumbnail\" /></a></div>";
echo "<p class=\"fleet_text\" />";
echo "$blk[3], $blk[0]<br />$blk[4]<br />$blk[5]<br />$blk[6]<br />$blk[7]<br />";
echo "<br /> ";
echo "</div>";
return 1;
} else return 0;
}
Then later within the body of the document all I need is,
<!-- Fleet box -->
<center>
<div class="fleet_box">
<!-- Plane -->
<?php do ; while (getNextPlaneBlock() == 1);?>
</div>
</center>
And I have a completely dynamic listing of the entire fleet managed by a simple text file with no further intervention required.
Now, I do have a slightly expanded data file... but more importantly easily expanded and if new data needs to be added I don't have to play any games of recounting skipped indices and I simply adjust the use of the $blk[x] elements in the output function getNextPlaneBlock(), one time only.
N2325N
f01_n2325n.jpg
tn_f01_n2325n.jpg
Piper Tomahawk
2-seater, 110 hp
data 3
data 4
$54 / hr (Wet)
N2378K
f02_n2378k.jpg
tn_f02_n2378k.jpg
Piper Tomahawk
2-seater, 110 hp
data 3
data 4
$54 / hr (Wet)
N11242
f10_n11242.jpg
tn_f10_n11242.jpg
Cessna 150
2-seater, 100 hp
data 3
data 4
$54 / hr (Wet)
I've been out of college and writing software for 15ys but this is my first foray into php. If anyone has any ideas or comments on something I've done wrong, inefficiently or how to simply make the method better, I'm ALL ears. Thanks for the input...
/jim/houston/tx