php - Get only the filename from a path -


i have string

$string = 'c:\folder\sub-folder\file.ext'; 

i want change to:

$string = 'file.ext'; 

using php, trying write method ignores left of last \.

use basename() str_replace() \ in path is not recognized basename()

$filename = basename(str_replace('\\', '/', 'c:\folder\sub-foler\file.ext')); echo $filename; // file.ext 

demo


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -