如何使用PHP从字符串中获取特定的子字符串数字? [重复]

This question already has an answer here:

$fileName = "Backup_1486874341.tar.gz"

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

</div>

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

Here is the sample snippet:

<?php

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

?>