Bricktop Posted July 16, 2009 Share Posted July 16, 2009 Hi haps, I'm building a file rename script, I have the filename stored as $file, but this will return "example.txt" What I would like to is to get "example" and ".txt" and store them as: $filename $extension Any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/166222-solved-get-filename-and-split/ Share on other sites More sharing options...
rhodesa Posted July 16, 2009 Share Posted July 16, 2009 <?php $file = 'example.txt'; $i = strrpos($file,'.'); $filename = substr($file,0,$i); $extension = substr($file,$i+1); ?> Link to comment https://forums.phpfreaks.com/topic/166222-solved-get-filename-and-split/#findComment-876536 Share on other sites More sharing options...
Jibberish Posted July 16, 2009 Share Posted July 16, 2009 <?php $pieces = explode('.', $file) $filename = $pieces[0]; $extension = $pieces[1]; ?> Link to comment https://forums.phpfreaks.com/topic/166222-solved-get-filename-and-split/#findComment-876540 Share on other sites More sharing options...
rhodesa Posted July 16, 2009 Share Posted July 16, 2009 <?php $pieces = explode('.', $file) $filename = $pieces[0]; $extension = $pieces[1]; ?> i wouldn't do it that way, as a filename like some.file.txt would produce unexpected results Link to comment https://forums.phpfreaks.com/topic/166222-solved-get-filename-and-split/#findComment-876543 Share on other sites More sharing options...
Jibberish Posted July 16, 2009 Share Posted July 16, 2009 Thats true, whereas strrpos gets the last occurrence of the search term, ignore me Link to comment https://forums.phpfreaks.com/topic/166222-solved-get-filename-and-split/#findComment-876546 Share on other sites More sharing options...
Bricktop Posted July 17, 2009 Author Share Posted July 17, 2009 Thanks chaps! Link to comment https://forums.phpfreaks.com/topic/166222-solved-get-filename-and-split/#findComment-876923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.