거기에 파일에서 버전 1.0.0.0을 얻는 방법 (PHP 함수)이 있습니까?파일의 PHP param 버전을 읽는 방법?
/**
* @author softplaxa
* @copyright 2011 Company
* @version 1.0.0.0
*/
미리 감사드립니다.
거기에 파일에서 버전 1.0.0.0을 얻는 방법 (PHP 함수)이 있습니까?파일의 PHP param 버전을 읽는 방법?
/**
* @author softplaxa
* @copyright 2011 Company
* @version 1.0.0.0
*/
미리 감사드립니다.
아니요, 나열된 버전 1.0.0.0을 파일에서 추출하는 네이티브 PHP 함수가 없습니다. 그러나, 당신은 하나를 쓸 수 있습니다 :
A. 당신은 라인으로 파일 라인을 구문 분석 할 수 및 사용는 preg_match()를
B. 당신이 시스템 호출 여기
$string = file_get_contents("/the/php/file.php");
preg_match("/\*\[email protected]\s+([0-9.]+)/mis", $matches, $string);
var_dump($matches[1]);
아마도 더 효율적인 방법을 쓸 수는 있지만 작업이 완료됩니다.
로 그렙을 사용 할 수 있습니다 사용하는 테스트 기능입니다 fgets, 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;
}
'\/*'는 OP 예제에서 작동하지 않습니다. 내가 코멘트 블록 구문 alltogether와 일치하는 것을 피할 것입니다. '@ version'을 확인하면 충분할 것입니다. – mario
사실, 정규식을 업데이트했습니다. 나는 아마도 fopen을 할 것이고, */당신이 너무 멀리 갔다면, (strstr ('@ version', $ line)) 정규 표현식을 수행한다면, fgets를 할 것이다. 더 효율적으로로드합니다. – Halcyon