asterixvader Posted September 15, 2009 Share Posted September 15, 2009 Hi. I'd like to know how to get only some parts of the names of files I upload to a page. (Of course, the files, the upload, etc, don't matter, what matters is the name of the files, which are strings.) All files names are as follow: "img ### comments.ext" i like to take only the "comments" part, and take out the "img ###" and ".ext" parts. I think it'd work perfectly with the substring function, but the detail is that the quantity of digits in the number part (###) differ from file to file, it's not always 3 digits (also the "comments" part vary). I wondered if there's a way to make Php recognize the position of the second space, after the numbers (since that will always be the initial position, and the final is always -4), but I don't know! You are the Php Freaks. I hope someone will help out! Link to comment https://forums.phpfreaks.com/topic/174265-solved-getting-substring/ Share on other sites More sharing options...
DavidAM Posted September 15, 2009 Share Posted September 15, 2009 $fileName = 'img 123 comments.ext'; $comments = preg_replace(array('~^img [0-9]+ ~', '~\.ext$~'), '', $fileName) I think that's right; I'm not the best RegEx'r in the world. Link to comment https://forums.phpfreaks.com/topic/174265-solved-getting-substring/#findComment-918661 Share on other sites More sharing options...
asterixvader Posted September 15, 2009 Author Share Posted September 15, 2009 This seems to work perfectly. Thank you! Link to comment https://forums.phpfreaks.com/topic/174265-solved-getting-substring/#findComment-918990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.