Posted in php functions
2581
5:45 am, April 7, 2023
 

Return a file extention from a string

This php function returns a file extention from a string. 

I think it will only work if the string does not have any additional . in it. 

I think a better way to do this function would be to split the string into an array on the . and then select the last dot content. 

Actually after testing this it does already locate the last . location. Test Link with multiple .'s

View Utility Page

PHP

// return a file extention
	function get_file_extension($file_name) {
		return substr(strrchr($file_name,'.'),1);
	}

echo get_file_extension($file_name = "1.2.3456.678-asz.txt");

External Link for Return a file extention from a string

View Statistics
This Week
31
This Month
226
This Year
686

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
therock Somewhere along this crazy road I learned (often times the hard way) the most important things I can do is be authentic, trust my gut, be the hardest worker in the room, celebrate the mistakes, be a grateful man and always remember that it's nice to be important, but it's more important to be nice.
The Rock
Random CSS Property

order

The order CSS property sets the order to lay out an item in a flex or grid container. Items in a container are sorted by ascending order value and then by their source code order.
order css reference