is there a way (a php function) to get the version 1.0.0.0 from a file?
/** * @author softplaxa * @copyright 2011 Company * @version 1.0.0.0 */ thanks in advance!
$string = file_get_contents("/the/php/file.php"); preg_match("/\*\s+@version\s+([0-9.]+)/mis", $matches, $string); var_dump($matches[1]); You can probably write something way more efficient, but this gets the job done.
\/* will not work on OPs example. I would avoid trying to match the comment block syntax alltogether. Checking for @version would suffice I guess.Here's a tested function that uses fgets, adapted from Drupal Libraries API module:
/** * 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; }