ted_chou12 Posted December 19, 2006 Share Posted December 19, 2006 for example "html.txt"I want the "html" part of the filename, does anybody know a easy way to achieve that?ThanksTed. Quote Link to comment Share on other sites More sharing options...
taith Posted December 19, 2006 Share Posted December 19, 2006 theres prolly an easier way... but this one has always worked wonders for me :-)[code]<?function get_filename($filepath,$extension=4){ $filepath = get_actualfilename($filepath); $length = strlen($filepath) - $extension; return substr($filepath,0,$length);}?>[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 thanks. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 but I think you need to define the function: get_actualfilename... as well, of whcih i dont have... Quote Link to comment Share on other sites More sharing options...
taith Posted December 19, 2006 Share Posted December 19, 2006 sorry... here ya go...[code]<?function get_actualfilename($string){ if(stristr($string,'?')){ $pos = strpos($string, "?"); $string = substr($string, 0, $pos); } $string=basename($string); return $string;}?>[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 nope, doesnt work for me :'( Quote Link to comment Share on other sites More sharing options...
taith Posted December 19, 2006 Share Posted December 19, 2006 you can cut out the whole get_actualfilename() part if your not intending on putting a full url in :) Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 okay, ill give it a try ;D Quote Link to comment Share on other sites More sharing options...
papaface Posted December 19, 2006 Share Posted December 19, 2006 [code]list($name, $extension) = explode('.', $filename);[/code]$name = without extension$extension = extension Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 thanks. Quote Link to comment Share on other sites More sharing options...
craygo Posted December 19, 2006 Share Posted December 19, 2006 can use this[code]<?phpfunction get_filename($filename){$file = substr($filename, 0, strpos($filename, strrchr($filename, ".")));return $file;}echo get_filename("johnny.inc.txt");?>[/code]this will get the file name no matter what. if you have a file johnny.html if will return johnnyif you have a file name johnny.inc.php it will return johnny.incRay Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 oh, i understand, because some filenames have more than one dot, is that right?Ted Quote Link to comment Share on other sites More sharing options...
craygo Posted December 19, 2006 Share Posted December 19, 2006 yes and some file extension are more that 3 characters, not usually but html is one of them.Ray Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.