PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

putenv> <phpinfo
Last updated: Fri, 16 May 2008

view this page in

phpversion

(PHP 4, PHP 5)

phpversion — Gets the current PHP version

Description

string phpversion ([ string $extension ] )

Returns a string containing the version of the currently running PHP parser or extension.

Parameters

extension

An optional extension name.

Return Values

If the optional extension parameter is specified, phpversion() returns the version of that extension, or FALSE if there is no version information associated or the extension isn't enabled.

Examples

Example #1 phpversion() example

<?php
// prints e.g. 'Current PHP version: 4.1.1'
echo 'Current PHP version: ' phpversion();

// prints e.g. '2.0' or nothing if the extension isn't enabled
echo phpversion('tidy');
?>

Notes

Note: This information is also available in the predefined constant PHP_VERSION.



add a note add a note User Contributed Notes
phpversion
djtopper at email dot cz
14-Apr-2008 10:57
Real PHP version:
$phpversion = preg_replace('/[a-z-]/', '', phpversion());
kalle at php dot net
10-Jan-2008 05: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));
    }
?>

putenv> <phpinfo
Last updated: Fri, 16 May 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites