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" 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. 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]; 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! Link to comment https://forums.phpfreaks.com/topic/252669-split-function/#findComment-1295326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.