BulletzBill Posted April 21, 2008 Share Posted April 21, 2008 Hello, I need helping parsing a string which contains a timestamp that I need. Here is an example of the format: 22/1208735244_dig_apple.jpg The "1208735244" is what i need parsed into a $timestamp variable. So I need to grab all the characters after the forward slash and before the first underscore. Any help would be appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/102059-help-parsing-a-string-with-php/ Share on other sites More sharing options...
dptr1988 Posted April 21, 2008 Share Posted April 21, 2008 You can try regular expressions, but there are easier ways to do it. Try this: <?php $name = "22/1208735244_dig_apple.jpg"; $start = strpos($name, '/') + 1; $end = strpos($name, '_'); $timestamp = substr($name, $start, $end - $start); ?> I'm not sure if the $start and $end indices are exactly correct, you may need to adjust them +-1. Link to comment https://forums.phpfreaks.com/topic/102059-help-parsing-a-string-with-php/#findComment-522380 Share on other sites More sharing options...
Fadion Posted April 21, 2008 Share Posted April 21, 2008 Regular expressions arent the fastest way, so dptr1988 method should work just fine. If the filename will remain always like that (which i doubt) u can just use substr($name, 3, 10);. Link to comment https://forums.phpfreaks.com/topic/102059-help-parsing-a-string-with-php/#findComment-522385 Share on other sites More sharing options...
BulletzBill Posted April 21, 2008 Author Share Posted April 21, 2008 Thanks guys, that worked perfectly. Link to comment https://forums.phpfreaks.com/topic/102059-help-parsing-a-string-with-php/#findComment-522409 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.