- preg_match: documentation ( source)
- sprintf: documentation ( source)
<?php
$filename = "9567567208_2014-10-16_12-16-02_1137592.wav";
$r = '/(?P<phone>\d{10})_(?P<Y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2})_(?P<H>\d{2})-(?P<i>\d{2})-(?P<s>\d{2})_.*/';
if (preg_match($r, $filename, $bits)) {
$phone = $bits['phone'];
$year = $bits['Y'];
$month = sprintf('%02s', $bits['m']);
$day = sprintf('%02s', $bits['d']);
$hour = sprintf('%02s', $bits['H']);
$minute = sprintf('%02s', $bits['i']);
$second = sprintf('%02s', $bits['s']);
$timestamp = "$year-$month-$day $hour:$minute:$second";
}
echo $timestamp.PHP_EOL;
echo $phone.PHP_EOL;
?>