Skip to content

Instantly share code, notes, and snippets.

@sasa-b
Created December 2, 2019 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sasa-b/883fd9810f773e3e200bdf8ea073f93b to your computer and use it in GitHub Desktop.
Save sasa-b/883fd9810f773e3e200bdf8ea073f93b to your computer and use it in GitHub Desktop.
A small script for easier management of multiple version of PHP with Homebrew on macOS
#!/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