Created
April 11, 2012 10:20
-
-
Save aertmann/2358452 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$paths = explode(PATH_SEPARATOR, getenv('PATH')); | |
foreach ($paths as $path) { | |
$phpExecutable = $path . DIRECTORY_SEPARATOR . 'php' . (isset($_SERVER['WINDIR']) ? '.exe' : ''); | |
if (file_exists($phpExecutable) && is_file($phpExecutable)) { | |
exec(escapeshellarg($phpExecutable) . ' -v', $phpVersion); | |
if (substr(array_shift($phpVersion), 0, strlen('PHP ' . PHP_VERSION)) === 'PHP ' . PHP_VERSION) { | |
echo $phpExecutable; | |
} | |
} | |
} |
The last version as nicely formatted code block:
<?php
$paths = explode(PATH_SEPARATOR, getenv('PATH'));
foreach ($paths as $path) {
$phpExecutable = $path . DIRECTORY_SEPARATOR . 'php' . (isset($_SERVER['WINDIR']) ? '.exe' : '');
if (file_exists($phpExecutable) && is_file($phpExecutable)) {
$phpVersion = trim(exec(escapeshellcmd($phpExecutable) . ' -r "echo PHP_VERSION;"'));
if ($phpVersion === PHP_VERSION) {
return $phpExecutable;
}
}
}
BTW: This code is rather a reminder, "php -v" returns completely different strings that needs some parsing. but it would be great if we could get that to work sometime..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
foreach ($paths as $path) {
$phpExecutable = $path . DIRECTORY_SEPARATOR . 'php' . (isset($_SERVER['WINDIR']) ? '.exe' : '');
if (file_exists($phpExecutable) && is_file($phpExecutable)) {
$phpVersion = trim(exec(escapeshellcmd($phpExecutable) . ' -r "echo PHP_VERSION;"'));
if ($phpVersion === PHP_VERSION) {
return $phpExecutable;
}
}
}