Jump to content

Archived

This topic is now archived and is closed to further replies.

glenelkins

Getting the extension of a file

Recommended Posts

what function is there to test the extension of a file?

Share this post


Link to post
Share on other sites
Might take a look here...

[a href=\"http://codewalkers.com/seecode/95.html\" target=\"_blank\"]http://codewalkers.com/seecode/95.html[/a]

Lite...

Share this post


Link to post
Share on other sites
[!--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]

Share this post


Link to post
Share on other sites
in the other example (linked site) they use a function called: strch() but that returns an undefined error wierd

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.