/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] If, Else Statements…

Hi there… I have this code

[code=php]
<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>”; ?>

<?
}
?>
[/code]

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

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 17.2006 — [code=php]
if(preg_match('/.(php|html?)$/i', $file))
{
// it's a PHP or HTML file
}
else
{
// it's some other type of file
}
[/code]
Copy linkTweet thisAlerts:
@scottyrobauthorJun 18.2006 — YAY, that worked great! Exactly what i wanted! Thanks very much ?
Copy linkTweet thisAlerts:
@SheldonJun 18.2006 — 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
×

Success!

Help @scottyrob spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...