Jump to content

Help parsing a string with PHP


BulletzBill

Recommended Posts

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

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.