-4
$fileName = "Backup_1486874341.tar.gz"

Here is my file name. How can i get only timestamp from that file name Like 1486874341

Mohammad
  • 21,175
  • 15
  • 55
  • 84
sharif779
  • 174
  • 2
  • 10

2 Answers2

0

Use simple regex in preg_match() to select target digit in file name.

$fileName = "Backup_1486874341.tar.gz";
preg_match("/_(\d+)./", $fileName, $matches);
echo $matches[1];

See result in demo

Mohammad
  • 21,175
  • 15
  • 55
  • 84
0

Here is the sample snippet:

<?php

$str = 'Backup_1486874341.tar.gz';
preg_match_all('!\d+!', $str, $matches);
print_r($matches[0][0]);

?>
Yaman Jain
  • 1,254
  • 11
  • 16