Click to See Complete Forum and Search --> : [RESOLVED] If, Else Statements...


scottyrob
06-17-2006, 03:57 AM
Hi there... I have this code


<link href="main.css" rel="stylesheet" type="text/css">
<?
$list = glob("*.*");
foreach ($list as $file) {
$files[$file] = filemtime($file);
}
arsort($files, SORT_NUMERIC);
foreach ($files as $file=>$mod)
{ ?>
<a href="edit.php?pagename=<? echo $file; ?>"><img src="images/edit.gif" border="0" width="20" height="20"></a>
<a href="<? echo $file; ?>" target="_blank"><? echo $file; ?></a>
<? echo " - "; ?>
<? echo date("d / m / y - h:i",$mod); ?>
<? echo "<br>"; ?>

<?
}
?>


It echos all the names of the files in the same directory as the file itself... it also shows an icon next to each one thats a link to edit.php... How can i make it so that if the file that is being echoed is .html or .php then it stayes the same, but if its any other file type then the image changes and there is no link on the image... Im guessing this would be done with If, Else statements?

Thanks
Fet

NogDog
06-17-2006, 08:30 AM
if(preg_match('/\.(php|html?)$/i', $file))
{
// it's a PHP or HTML file
}
else
{
// it's some other type of file
}

scottyrob
06-18-2006, 03:36 AM
YAY, that worked great! Exactly what i wanted! Thanks very much :D

Sheldon
06-18-2006, 05:26 AM
Nice, I was going to suggset explode on the . but then i remebered a thread I was reading the other night and decided againt it!


Goood code C