Jump to content

Getting the extension of a file


glenelkins

Recommended Posts

[!--quoteo(post=350185:date=Feb 28 2006, 07:17 AM:name=glenelkins)--][div class=\'quotetop\']QUOTE(glenelkins @ Feb 28 2006, 07:17 AM) [snapback]350185[/snapback][/div][div class=\'quotemain\'][!--quotec--]
what function is there to test the extension of a file?
[/quote]

you can write one:
[code]
<?php
function getExt($filename) {
  $pos = strrpos($filename, '.');
  if ($pos !== false) {
    return substr($filename, $pos + 1);
  } else
    return NULL;
}
?>
[/code]
Link to comment
Share on other sites

Look at the [a href=\"http://www.php.net/pathinfo\" target=\"_blank\"]pathinfo[/a]() function.

Example from the manual:
[code]<?php
$path_parts = pathinfo('/www/htdocs/index.html');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
?> [/code]

Ken
Link to comment
Share on other sites

[!--quoteo(post=350239:date=Feb 28 2006, 10:34 AM:name=glenelkins)--][div class=\'quotetop\']QUOTE(glenelkins @ Feb 28 2006, 10:34 AM) [snapback]350239[/snapback][/div][div class=\'quotemain\'][!--quotec--]
in the other example (linked site) they use a function called: strch() but that returns an undefined error wierd
[/quote]

they are trying to use strchr(), but it's simply an alias of strstr() anyway
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.