Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- class System
- {
- function my_getopt()
- {
- global $argv;
- $result = array();
- $current_key = false;
- foreach($argv as $opt)
- {
- $matches = array();
- if(preg_match("/^-([a-zA-Z]*)/", $opt, $matches))
- {
- $current_key = $matches[1];
- if(!isset($result[$current_key]))
- {
- $result[$current_key] = false;
- }
- }
- else if (false != $current_key)
- {
- if(false == $result[$current_key])
- {
- $result[$current_key] = $opt;
- }
- else
- {
- if(false == is_array($result[$current_key]))
- {
- $result[$current_key] = array($result[$current_key]);
- }
- $result[$current_key][] = $opt;
- }
- }
- }
- return $result;
- }
- }
- $system = new system;
- print_r($system->my_getopt());
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement