Reply to newbie: scandir _not_ including directories

Your name:

Reply:


Posted by Jenny Purcell on 12/30/07 00:02

I have a function below that I (partially) wrote to handle a
particular situation.

I'm working with horse records in text files. I want to list all the
files with horse information in them, then a dash "-", then, a brief
description of the horse (taken from a separate text file). If that
description isn't in the text file, it leaves a blank line (so I know
to add it). The lines of extra information, as listed in separate
file, do not have to be in any order.

This all works: http://snowyriver.zzl.org/race_cards/index.php

I find that that scandir() also scans for subdirectories. I _only_
want to scan for .txt files. Scandir is good for me to use because it
alphabetizes the files without any additional work.

I would appreciate any help that could be offered as far as ways to
adjust my $files array so it's only made up of .txt files.

Thank you for reading this post!

Jenny

<!-- Start PHP Functions -->


<?php
// Links creating script taken from:
http://www.phpfreaks.com/tutorials/146/0.php
// Originally added October 21st, 2007
// Modified by Jenny Purcell to be a subroutine to call it multiple
times.
// Further modified to include info on each horse from a separate file
(by directory).
//

function make_links($dir,$breed) { // create a user-defined function
named make_links
$files = scandir($dir) ;
$breedfile = @fopen("$breed","r",4096);
$count = -1 ; // for array
if ($breedfile) { // If file exists, execute while
while (!feof($breedfile)) { // while we haven't reached
the End of File, read lines into the buffer.
$count = $count + 1 ; // increment
// $horses[$count][1] = "";
$horses[] = explode(" - ",fgets($breedfile)); //
separate line elements into a 2 dimensional array
} // close while
fclose($breedfile); // close file when it reaches the EOF
} // close if
foreach($files as $ind_file){ // start outer foreach loop
$letter = strtoupper(substr($ind_file,0,1));
if($ind_file != '.' && $ind_file != '..') { // start
2nd if loop
$count2 = -1 ;
$temp = "";
while ($count2 < $count) { // start inner foreach
$count2 = $count2 + 1 ;
if ($horses[$count2][0]== $ind_file) { //
start 1st if loop
$temp = $horses[$count2][1]; // temp
is the info on the horse file
} // end 1st if loop
} // end inner foreach
?>
<li><a name="<?php echo $letter; ?>"
href="<?php echo "$dir"."/".$ind_file; ?>"><?php echo $ind_file;?></a>
<?php echo " - $temp" ;?></li>
<?php
} // end 2nd if loop
} // end outer foreach loop

} // end user-defined make_links function

?>
<!-- End PHP Functions -->
--
Jenny Purcell
Snowy River Farms (PBEM Fantasy Horse Racing)
http://snowyriver.zzl.org/

[Back to original 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

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