You are here

function patterns_utils_get_phpdoc_version in Patterns 7

Same name and namespace in other branches
  1. 7.2 includes/utils.inc \patterns_utils_get_phpdoc_version()

Helper function to get PHPDoc @version tag from a file

File

includes/utils.inc, line 52
Collectiion of general purpose functions.

Code

function patterns_utils_get_phpdoc_version($path) {
  $version = 'unknown';
  $needle = '@version ';
  if (file_exists($path)) {
    $fp = @fopen($path, 'r');
    if ($fp) {
      while (!feof($fp)) {
        $occurence = stristr(fgets($fp), $needle);
        if ($occurence) {

          // FALSE if stristr found nothing
          return rtrim(substr($occurence, strlen($needle)));
        }
      }
    }
  }
  return $version;
}