pie*_*e6k 5 php maintainability version
是否有可能在PHP获取服务器PHP版本发布日期?
所以,假设我有php 5.3.28.
比phpdate()应该回来的东西11 Jul 2013.
基于Antony D'Andrea链接,我稍微修改了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('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ',
'<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'.
"\n".'<tr><td>PHP Egg</td><td>$1</td></tr>',
'<tr><td>PHP Credits Egg</td><td>$1</td></tr>',
'<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" .
'<tr><td>Zend Egg</td><td>$1</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;
}
Run Code Online (Sandbox Code Playgroud)
然后phpdate运行
function phpdate($format = "d M Y") {
return date($format, strtotime( phpinfo_array("Build Date") ));
}
Run Code Online (Sandbox Code Playgroud)
因为我刚刚复制了它,所以我不知道这个神奇的正则表达式会发生什么。
phpinfo_array("Build Date"); //returns Apr 10 2014 17:15:04
phpdate("d M Y"); //returns 10 Apr 2014
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
620 次 |
| 最近记录: |