search for in the  
<phpinfoputenv>
Last updated: Thu, 19 May 2005

phpversion

(PHP 3, 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. 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.

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

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');
?>

See also version_compare(), phpinfo(), phpcredits(), php_logo_guid(), and zend_version().



User Contributed Notes
phpversion
ground-pilot at net-pilots.com
22-Jan-2005 01:52
Difference from bleeding edge server and production server where I couldn't use the phpversion() function. Came up with this to grab it from the command line instead. Note that the 'command line' version result , and 'http server api' version result could be two or more different versions, and not matching each other. So this may return a misleading value for your environment? Be careful if you have updated the web server api and not the command line, or visa-versa. ;)

But for me - it works.

<?php
$PHP_VERSION
= get_my_phpver();

echo
"PHP_VERSION = $PHP_VERSION<br>";

function
get_my_phpver() {
// USE :
//  $PHP_VERSION = get_my_phpver();
// CAVEAT NOTES :   
//  exec() will only return last line
//  passthru() will always show output, even when you ob_start() the output.
//  shell_exec() will return ALL lines of output but not forced
  
$my_phpver = trim(substr(shell_exec('php -v'), 3, 6));
  
// returns "4.3.1" of "PHP 4.3.1 (cgi)..." and removes white spaces
  
return $my_phpver;
}
?>

Of course this would also do the trick...

<?php
$PHP_VERSION
= trim(substr(shell_exec('php -v'), 3, 6));
echo
"PHP_VERSION = $PHP_VERSION<br>";
?>

And as always, there are OTHER method, but this works for me.

Hope this helps someone else out as well. :)

<phpinfoputenv>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT