anatak Posted May 29, 2009 Share Posted May 29, 2009 Is is possible to select a substring between two characters ? I have a list of pictures and I want to extract the number of the picture from the picture name. example name of picture is picture_3.jpg picture_15.jpg So I want to extract the 3 from the first and 15 from the second. Is this possible in 1 time or do I have to write a substring select that extracts everything after _ and after that a substring select that extracts everything before . Kind regards anatak Quote Link to comment https://forums.phpfreaks.com/topic/160205-solved-select-a-substring-between-two-characters/ Share on other sites More sharing options...
Daniel0 Posted May 29, 2009 Share Posted May 29, 2009 Assuming they're always named like that you can do this: preg_match('#_(\d+)\.jpg$#', $filename, $matches); $number = $matches[1]; Quote Link to comment https://forums.phpfreaks.com/topic/160205-solved-select-a-substring-between-two-characters/#findComment-845299 Share on other sites More sharing options...
anatak Posted May 29, 2009 Author Share Posted May 29, 2009 aaarghhh regular expressions (just joking) Thanks this is why I love this forum I always find someone who shows me how stupid I am. I was so concentrated on the substr, strrchr and trim functions it did not even occur to me that I could use a regular expression. Thanks anatak Quote Link to comment https://forums.phpfreaks.com/topic/160205-solved-select-a-substring-between-two-characters/#findComment-845302 Share on other sites More sharing options...
laffin Posted May 29, 2009 Share Posted May 29, 2009 Yeah, regex is real good. Just takes time to learn tho. But once ya get the basics, man is it ever so helpful Quote Link to comment https://forums.phpfreaks.com/topic/160205-solved-select-a-substring-between-two-characters/#findComment-845323 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.