A small script for easier management of multiple version of PHP with Homebrew on macOS
This file contains 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
#!/usr/bin/env php | |
<?php | |
$ver = isset($argv[1]) ? $argv[1] : null; | |
if (!$ver) { | |
echo "Missing version argument\n"; | |
exit(1); | |
} | |
if (!is_numeric($ver) || !preg_match("/^[5-9]\.[0-9]$/", $ver)) { | |
echo "Invalid version format, version number must be a decimal value with precision of one, e.g. 7.0\n"; | |
exit(2); | |
} | |
$user = get_current_user(); | |
$bash_profile = file_get_contents("/Users/$user/.bash_profile"); | |
file_put_contents("/Users/$user/.bash_profile", preg_replace("/php@\d+\.\d+/", "php@$ver", $bash_profile)); | |
echo "\n"; | |
echo "PHP set to: $ver\n"; | |
echo "Restart the terminal for the changes to take effect.\n"; | |
echo "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment