/**
* Returns param version of a file, or false if no version detected.
* @param $path
* The path of the file to check.
* @param $pattern
* A string containing a regular expression (PCRE) to match the
* file version. For example: '@version\s+([0-9a-zA-Z\.-]+)@'.
*/
function timeago_get_version($path, $pattern = '@version\s+([0-9a-zA-Z\.-]+)@') {
$version = false;
$file = fopen($path, 'r');
if ($file) {
while ($line = fgets($file)) {
if (preg_match($pattern, $line, $matches)) {
$version = $matches[1];
break;
}
}
fclose($file);
}
return $version;
}