basic array help
Posted: Thu Jul 01, 2004 9:33 am
ok heres my script
Basically i am getting errors when i use "getFileList( 'B' )" when i have no files beginning with "B" in the directory, if i add some files beginning with "B" this will work fine, however i need someway to ensure that it wont give me errors when there are no files beginnign with "B". How do i do this
?
Hope that makes sense, if u need to know anything else pls ask.
Thanx,
Tom
Bech100 | Please use
Code: Select all
<?
#include_once( "src/config.inc" );
function getFileList( $letter )
{
$dir = opendir("tom/Cars");
$count = 0;
while($item = readdir($dir))
{
if($item=="." or $item=="..")
{
continue;
}
//$item = strtolower( $item );
if($item[0] == $letter)
{
$list[$count] = $item;
$count++;
}
}
return $list;
}
$resultList = getFileList( 'B' );
sort($resultList);
foreach ( $resultList as $car)
{
$carlink= $car;
$carname= str_replace ("_", " ",$car);
$carname= str_replace (".php"," ",$carname);
echo '<a href="tom/Cars/'.$car.'">'.$carname.'</a><br>';
}
// echo count($resultList);
// print_r( $resultList );
?>Basically i am getting errors when i use "getFileList( 'B' )" when i have no files beginning with "B" in the directory, if i add some files beginning with "B" this will work fine, however i need someway to ensure that it wont give me errors when there are no files beginnign with "B". How do i do this
Hope that makes sense, if u need to know anything else pls ask.
Thanx,
Tom
Bech100 | Please use
Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]