Last active
March 9, 2016 15:59
-
-
Save i-tabu/9f3c5a2dd2033dcf2b4c to your computer and use it in GitHub Desktop.
getopt - get options from params - example
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/php | |
<?php | |
print "\nscript started\n"; | |
//banner | |
//Usage: | |
//php your_script.php <server> <host> <db> | |
$banner = "Usage:\n"; | |
$banner .= "php {$argv[0]} -s <server> -h <host> -d <db>\n"; | |
$banner .= "Example:\n"; | |
$banner .= "php your_script.php -s myserver.tabrez.me -h localhost -d mydb \n"; | |
//Get params | |
$options = getopt("s:h:d:"); | |
//print_r($options); | |
//val params | |
if(count($options)<3){ | |
print $banner; | |
exit; | |
} | |
$server = $options['s']; | |
$host = $options['h']; | |
$db = $options['d']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The template for php command line scripts -