/    Sign up×
Community /Pin to ProfileBookmark

any function available who returns the extension of a file ?

any function available who returns the extension of a file ? ? ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsJul 02.2004 — try the pathinfo() function, example:[code=php]<?php
$path_parts = pathinfo("/www/htdocs/index.html");

echo $path_parts["dirname"]."n";
echo $path_parts["basename"]."n";
echo $path_parts["extension"]."n";
?>[/code]
Copy linkTweet thisAlerts:
@crh3675Jul 02.2004 — How about just:

[code=php]
<?
$file="http://www.somesite.com/farms/horses.pdf";

function getExtension($f){
$parts=explode(".",trim($f));
return strtoupper($parts[count($parts)-1]);
}

print getExtension($file);
?>

[/code]
Copy linkTweet thisAlerts:
@moondanceJul 03.2004 — or how about a simpler alternative:

[code=php]
Function GetExtension($filename)
{
return strrchr($filename, ".");
}
[/code]


strrchr looks for the last occurence of a character in a string, so this would work ok for extensions that are 2 or 4 characters long, as well as filename such as "my.pic.jpg"

?
×

Success!

Help @mirhamzah 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 5.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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