c_shelswell Posted December 6, 2006 Share Posted December 6, 2006 Hi does anyone know how i might remove the file path from a string. I'm guessing i use eregi or something like that just can't figure out how to do it.say i have [b]"E:\Documents and Settings\The King\Desktop\annaalien.jpg"[/b]and i want to end up with just [b]"annaalien.jpg"[/b] the file path will be different each time.Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/29650-remove-file-path-from-string/ Share on other sites More sharing options...
Zane Posted December 6, 2006 Share Posted December 6, 2006 here..from the manual[code]<?phpfunction GetFileName($file_name){ $newfile = basename($file_name); if (strpos($newfile,'\\') !== false) { $tmp = preg_split("[\\\]",$newfile); $newfile = $tmp[count($tmp) - 1]; return($newfile); } else { return($file_name); }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29650-remove-file-path-from-string/#findComment-136093 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.