In a addition to phpversion,..
if you've got a system like ubuntu or some else, you get
<?php
echo phpversion(); // 5.2.4-2ubuntu5.2
?>
To fix this, use the following:
<?php
echo substr(phpversion(),0,strpos(phpversion(), '-'));
?>
phpversion
(PHP 4, PHP 5)
phpversion — 現在の PHP バージョンを取得する
説明
string phpversion
([ string $extension
] )
現在動作中の PHP パーサあるいは拡張モジュールのバージョンを表す文字列を返します。
パラメータ
- extension
-
オプションで指定する拡張モジュール名。
返り値
オプションの extension パラメータが指定されている場合、phpversion() はその拡張モジュールのバージョンを返します。 関連するバージョン情報が存在しない場合、 あるいは拡張モジュールが有効でない場合は FALSE を返します。
例
例1 phpversion() の例
<?php
// たとえば 'Current PHP version: 4.1.1' などと表示します
echo 'Current PHP version: ' . phpversion();
// たとえば '2.0' などと表示します。拡張モジュールが有効でない場合は何も表示しません
echo phpversion('tidy');
?>
注意
注意: この情報は、定義済みの定数 PHP_VERSION でも取得可能です。
phpversion
pl DOT baasch AT skycube DOT net
14-Jul-2008 12:17
14-Jul-2008 12:17
djtopper at email dot cz
14-Apr-2008 04:57
14-Apr-2008 04:57
Real PHP version:
$phpversion = preg_replace('/[a-z-]/', '', phpversion());
kalle at php dot net
11-Jan-2008 12:21
11-Jan-2008 12:21
On some machines phpversion() will not return a string in this format:
major.minor.version
But rather
major.minor.version-[os manufacturer]
I experinced this on a couple of Linux variants like Ubuntu.
So don't rely on the first format, I made this function to get the "real" version which might come in handy if you don't want the 'os manufacturer' part:
<?php
function phpversion_real()
{
$v = phpversion();
$version = Array();
foreach(explode('.', $v) as $bit)
{
if(is_numeric($bit))
{
$version[] = $bit;
}
}
return(implode('.', $version));
}
?>