How to get the file name with extension from any path in PHP ?

Question:

How to get the file name with extension from any path in PHP ?

Solution:

basename() function of PHP has done the biggest job in one pretty line.

Example:
I have a string path and want to know the last file name on that path. Code is simply,

$path = "http://localhost/blog/images/demo.jpg";
basename($path);

Output :
demo.jpg


So, basename() function returns the trailing name component of path. See more about basename() function in PHP Manual.

See More examples of basename() function of PHP.

How to get the file name with extension from any path in PHP ?



Tags:
How to get the file name with extension from any path in PHP, php basename functions work, how to get the file name or last name from any string, how to get the trailing name from any path or string.
How to get the file name with extension from any path in PHP ? How to get the file name with extension from any path in PHP ? Reviewed by Maniruzzaman Akash on October 13, 2017 Rating: 5

No comments:

Powered by Blogger.