son.of.the.morning Posted December 7, 2011 Share Posted December 7, 2011 What's the best string function to use if i want to split a string up affter a specific character? In this case i have a var with "uploads/thisImage.jpg" i want to split this so i can create a new var value of "thisImage.jpg" Quote Link to comment https://forums.phpfreaks.com/topic/252669-split-function/ Share on other sites More sharing options...
Pikachu2000 Posted December 7, 2011 Share Posted December 7, 2011 If it's always a file name such as your example, basename. Quote Link to comment https://forums.phpfreaks.com/topic/252669-split-function/#findComment-1295319 Share on other sites More sharing options...
btellez Posted December 7, 2011 Share Posted December 7, 2011 you can use explode to split up a string after a given character. $path = "uploads/thisImage.jpg"; $parts = explode('/', $path); $fileName = $parts[1]; // Or use this if your path is buried in deeper directories... // $fileName = $parts[count($parts)-1]; Quote Link to comment https://forums.phpfreaks.com/topic/252669-split-function/#findComment-1295321 Share on other sites More sharing options...
son.of.the.morning Posted December 7, 2011 Author Share Posted December 7, 2011 Thanks man, i just done that seconds before i read your post. Thanks for you help anyway! Quote Link to comment https://forums.phpfreaks.com/topic/252669-split-function/#findComment-1295326 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.