PHP - 获取当前 php 版本发布日期
PHP - get current php version release date
是否可以在 php 中获取服务器 php 版本 发布日期 ?
假设我有 php 5.3.28
.
比 phpdate()
这样的东西应该 return 11 Jul 2013
.
你是说 Build Date
?
function phpdate($format="d M Y")
{
ob_start(); phpinfo(1);
if(preg_match('~Build Date (?:=> )?\K.*~', strip_tags(ob_get_clean()), $out))
return date($format, strtotime($out[0]));
}
echo phpdate();
04 Mar 2013
Test at eval.in(link即将到期)
更新:获取变更日志中的实际release date on Linux, could match phpversion():
// match phpversion() in changelog
function phpReleaseDate()
{
$log = `zgrep '^[0-9].*PHP' /usr/share/doc/php5/changelog.gz`;
$ver = preg_replace('/^\d+\.\d+\.\d+\K.*/', "", phpversion());
$find = '/^(\d{2} [A-Z][a-z]{2} \d{4}), PHP ('.preg_quote($ver).')/';
if(preg_match($find, $log, $out))
return array('ver' => $out[2], 'date' => $out[1]);
}
print_r(phpReleaseDate());
Array ( [ver] => 5.3.3 [date] => 22 Jul 2010 )
在 Debian 上试过 Linux。
我会使用 phpinfo() 并从那里获取构建日期。
在其中一个示例中有一个获取数组版本的 phpinfo 的好方法 here。
一旦你有了 function。做:
$php_info = phpinfo_array(true);
$builddate = $php_info['PHP Configuration']['Build Date'];
然后我会为它提出一个功能请求!
基于 Antony D'Andrea link 我稍微修改了 phpinfo_array
函数所以你可以像 phpinfo_array("Build Date");
我还创建了处理它的 phpdate($format) 函数。
function phpinfo_array($info=false){
/* Andale! Andale! Yee-Hah! */
ob_start();
phpinfo(-1);
$pi = preg_replace(
array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
'#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
"#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%',
'#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
.'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
'#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
'#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
"# +#", '#<tr>#', '#</tr>#'),
array('', '', '', '', '</>' . "\n", '<', ' ', ' ', ' ', '', ' ',
'<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td></td></tr>'.
"\n".'<tr><td>PHP Egg</td><td></td></tr>',
'<tr><td>PHP Credits Egg</td><td></td></tr>',
'<tr><td>Zend Engine</td><td></td></tr>' . "\n" .
'<tr><td>Zend Egg</td><td></td></tr>', ' ', '%S%', '%E%'),
ob_get_clean()
);
$sections = explode('<h2>', strip_tags($pi, '<h2><th><td>'));
unset($sections[0]);
$pi = array();
foreach($sections as $section){
$n = substr($section, 0, strpos($section, '</h2>'));
preg_match_all(
'#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#',
$section,
$askapache,
PREG_SET_ORDER
);
foreach($askapache as $m)
$pi[$m[1]]=(!isset($m[3])||$m[2]==$m[3])?$m[2]:array_slice($m,2);
}
if ( $info && isset( $pi[$info] ) ) return $pi[$info];
return $pi;
}
然后 phpdate
函数
function phpdate($format = "d M Y") {
return date($format, strtotime( phpinfo_array("Build Date") ));
}
因为我刚刚复制了它,所以我不知道这个神奇的正则表达式会发生什么。
phpinfo_array("Build Date"); //returns Apr 10 2014 17:15:04
phpdate("d M Y"); //returns 10 Apr 2014
您总能在页面上找到发布日期:https://is.php.released.info
是否可以在 php 中获取服务器 php 版本 发布日期 ?
假设我有 php 5.3.28
.
比 phpdate()
这样的东西应该 return 11 Jul 2013
.
你是说 Build Date
?
function phpdate($format="d M Y")
{
ob_start(); phpinfo(1);
if(preg_match('~Build Date (?:=> )?\K.*~', strip_tags(ob_get_clean()), $out))
return date($format, strtotime($out[0]));
}
echo phpdate();
04 Mar 2013
Test at eval.in(link即将到期)
更新:获取变更日志中的实际release date on Linux, could match phpversion():
// match phpversion() in changelog
function phpReleaseDate()
{
$log = `zgrep '^[0-9].*PHP' /usr/share/doc/php5/changelog.gz`;
$ver = preg_replace('/^\d+\.\d+\.\d+\K.*/', "", phpversion());
$find = '/^(\d{2} [A-Z][a-z]{2} \d{4}), PHP ('.preg_quote($ver).')/';
if(preg_match($find, $log, $out))
return array('ver' => $out[2], 'date' => $out[1]);
}
print_r(phpReleaseDate());
Array ( [ver] => 5.3.3 [date] => 22 Jul 2010 )
在 Debian 上试过 Linux。
我会使用 phpinfo() 并从那里获取构建日期。
在其中一个示例中有一个获取数组版本的 phpinfo 的好方法 here。
一旦你有了 function。做:
$php_info = phpinfo_array(true);
$builddate = $php_info['PHP Configuration']['Build Date'];
然后我会为它提出一个功能请求!
基于 Antony D'Andrea link 我稍微修改了 phpinfo_array
函数所以你可以像 phpinfo_array("Build Date");
我还创建了处理它的 phpdate($format) 函数。
function phpinfo_array($info=false){
/* Andale! Andale! Yee-Hah! */
ob_start();
phpinfo(-1);
$pi = preg_replace(
array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms',
'#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#',
"#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%',
'#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>'
.'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#',
'#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#',
'#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#',
"# +#", '#<tr>#', '#</tr>#'),
array('', '', '', '', '</>' . "\n", '<', ' ', ' ', ' ', '', ' ',
'<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td></td></tr>'.
"\n".'<tr><td>PHP Egg</td><td></td></tr>',
'<tr><td>PHP Credits Egg</td><td></td></tr>',
'<tr><td>Zend Engine</td><td></td></tr>' . "\n" .
'<tr><td>Zend Egg</td><td></td></tr>', ' ', '%S%', '%E%'),
ob_get_clean()
);
$sections = explode('<h2>', strip_tags($pi, '<h2><th><td>'));
unset($sections[0]);
$pi = array();
foreach($sections as $section){
$n = substr($section, 0, strpos($section, '</h2>'));
preg_match_all(
'#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#',
$section,
$askapache,
PREG_SET_ORDER
);
foreach($askapache as $m)
$pi[$m[1]]=(!isset($m[3])||$m[2]==$m[3])?$m[2]:array_slice($m,2);
}
if ( $info && isset( $pi[$info] ) ) return $pi[$info];
return $pi;
}
然后 phpdate
函数
function phpdate($format = "d M Y") {
return date($format, strtotime( phpinfo_array("Build Date") ));
}
因为我刚刚复制了它,所以我不知道这个神奇的正则表达式会发生什么。
phpinfo_array("Build Date"); //returns Apr 10 2014 17:15:04
phpdate("d M Y"); //returns 10 Apr 2014
您总能在页面上找到发布日期:https://is.php.released.info