Jump to content


Photo

Getting the extension of a file


  • Please log in to reply
5 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 28 February 2006 - 12:17 PM

what function is there to test the extension of a file?
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 28 February 2006 - 01:30 PM

Might take a look here...

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

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 28 February 2006 - 01:37 PM

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

you can write one:
<?php
function getExt($filename) {
  $pos = strrpos($filename, '.');
  if ($pos !== false) {
    return substr($filename, $pos + 1);
  } else
    return NULL; 
}
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 28 February 2006 - 03:34 PM

in the other example (linked site) they use a function called: strch() but that returns an undefined error wierd
http://thewebsolutionprovider.com - A Solution For Everything Web!

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 28 February 2006 - 03:41 PM

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

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

Ken


#6 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 28 February 2006 - 04:03 PM

[!--quoteo(post=350239:date=Feb 28 2006, 10:34 AM:name=glenelkins)--][div class=\'quotetop\']QUOTE(glenelkins @ Feb 28 2006, 10:34 AM) View Post[/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
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users