note 49282 added to function.phpversion
| From: | ground-pilotatnet-pilots dot com at osu1 dot php dot net | Date: | Sat, 22 Jan 2005 19:52:52 +0000 |
| Subject: | note 49282 added to function.phpversion | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83788@lists.php.net to get a copy of this message | ||
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. :)
----
Manual Page -- http://www.php.net/manual/en/function.phpversion.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49282
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49282&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49282&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49282&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49282&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49282&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49282&report=yes
Search -- http://master.php.net/manage/user-notes.php