You are here: Re: Using File() with blank lines « PHP Programming Language « IT news, forums, messages
Re: Using File() with blank lines

Posted by Spin on 06/05/05 21:52

On 4 Jun 2005 20:45:51 -0700, "NC" <nc@iname.com> wrote:

>foreach ($data as $line) {
> $line = trim($line);

Thanks NC, that give me something to think about. As a C/C++/OP
programmer for 15 yrs now I struggle with language constructions like
($data as $line) so I'll have to think on this method a bit.

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 />&nbsp;";
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, the original was simply an
example... but more importantly easily expanded in the future and if new
data needs to be added 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)


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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация