2015-01-31 22 views

Antwort

0

gründend auf Antony D'Andrea Link Ich habe etwas phpinfo_array Funktion modifiziert, so dass Sie es wie phpinfo_array("Build Date");

verwenden kann ich auch phpdate ($ format) -Funktion, die es behandelt erstellt haben.

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]+#", '#&nbsp;#', '# +#', '# class=".*?"#', '%&#039;%', 
      '#<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; 
} 

Und phpdate Funktion dann

function phpdate($format = "d M Y") { 
    return date($format, strtotime(phpinfo_array("Build Date"))); 
} 

Wie ich es nur kopiert habe, habe ich keine Ahnung, was in dieser magischen regex geschieht.

phpinfo_array("Build Date"); //returns Apr 10 2014 17:15:04 
phpdate("d M Y"); //returns 10 Apr 2014 
2

Sie meinen 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 läuft bald)


aktualisieren: die tatsächliche release date unter Linux zu bekommen, könnte phpversion() im Match Änderungsprotokoll:

// 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 [Datum] => 22 Jul 2010)

versucht, dies mit Debian Linux.

+0

Ja. Genau das! –

+0

Ist das Erstellungsdatum das gleiche wie das Veröffentlichungsdatum? http://php.net/releases/ – pie6k

+0

@AdamPietrasiak Ich denke, es ist das Datum, als PHP kompiliert wurde. –

0

Ich würde phpinfo() verwenden und das Build-Datum von dort bekommen.

Es gibt eine ziemlich gute Möglichkeit, eine Array-Version von phpinfo in einem der Beispiele here zu bekommen.

Sobald Sie das function haben. Do:

$php_info = phpinfo_array(true); 
$builddate = $php_info['PHP Configuration']['Build Date']; 

Dann würde ich eine Feature-Anfrage dafür machen!