sasi Posted April 11, 2007 Share Posted April 11, 2007 Hello everybody, I want the only filename with extension in the following string, ex:/home/localftp1/DTFFiles/tr_his1240.dtf so here the tr_his1240.dtf is the only file name, so from the database i will get a set of records from that each record contains the above (path) string and in that i want only the filenames from each record. please respond to this as early as possible. Link to comment https://forums.phpfreaks.com/topic/46573-i-want-the-only-filename-with-extension-in-the-following-string/ Share on other sites More sharing options...
obsidian Posted April 11, 2007 Share Posted April 11, 2007 Try something like this: $string = "/home/localftp1/DTFFiles/tr_his1240.dtf"; preg_match('|/([^/]+)\z|', $string, $match); echo $match[1]; Link to comment https://forums.phpfreaks.com/topic/46573-i-want-the-only-filename-with-extension-in-the-following-string/#findComment-226715 Share on other sites More sharing options...
clown[NOR] Posted April 13, 2007 Share Posted April 13, 2007 wouldnt maybe pathinfo work? $filename = pathinfo("/home/localftp1/DTFFiles/tr_his1240.dtf"); $filename = $filename['basename']; echo $filename; Link to comment https://forums.phpfreaks.com/topic/46573-i-want-the-only-filename-with-extension-in-the-following-string/#findComment-228337 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.