Skip to content

Instantly share code, notes, and snippets.

@i-tabu
Last active March 9, 2016 15:59
Show Gist options
  • Save i-tabu/9f3c5a2dd2033dcf2b4c to your computer and use it in GitHub Desktop.
Save i-tabu/9f3c5a2dd2033dcf2b4c to your computer and use it in GitHub Desktop.
getopt - get options from params - example
#!/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'];
@i-tabu
Copy link
Author

i-tabu commented Mar 9, 2016

The template for php command line scripts -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment