Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - get current php version release date

Is it possible in php to get server php version release date?

So let's say I've got php 5.3.28.

Than something like phpdate() should return 11 Jul 2013.

like image 961
Adam Pietrasiak Avatar asked Oct 31 '22 10:10

Adam Pietrasiak


1 Answers

You mean 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 expires soon)


Update: To get the actual release date on Linux, could match phpversion() in the changelog:

// 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 )

Tried this with Debian Linux.

like image 113
Jonny 5 Avatar answered Nov 08 '22 15:11

Jonny 5