oGetopt
[ class tree: oGetopt ] [ index: oGetopt ] [ all elements ]

샘플 예제 코드

  1. <?php
  2. /**
  3.  * OOPS C library getopt wrapping API
  4.  *
  5.  * oGetopt class
  6.  *
  7.  * PHP version 5
  8.  *
  9.  * LICENSE: BSD license
  10.  *
  11.  * @category    Core
  12.  * @package        eGetopt
  13.  * @author        JoungKyun.Kim <http://oops.org>
  14.  * @copyright    1997-2009 OOPS.ORG
  15.  * @license        BSD License
  16.  * @version        CVS: $Id$
  17.  * @link        http://pear.oops.org/package/oGetopt
  18.  * @since        File available since relase 1.0.0
  19.  */
  20.  
  21. $incs file_exists ('./oGetopt.php''./' '';
  22. $incs .= 'oGetopt.php';
  23. require_once "{$incs}";
  24.  
  25. echo "#############################################################\n";
  26. echo "Command Lines:\n    ";
  27. foreach $argv as $v {
  28.     echo "$v ";
  29. }
  30. echo "\n\n";
  31.  
  32. # Initialized getopt order variables
  33.  
  34. oGetopt::$longopt = (object) array (
  35.     'first'  => 'f',
  36.     'second' => 's',
  37.     'third'  => 't',
  38. );
  39.  
  40. $first false;
  41. $third false;
  42. while ( ($opt oGetopt::exec ($argc$argv"f:s:t")) !== false {
  43.     switch $opt {
  44.         case 'f' :
  45.             $first oGetopt::$optarg;
  46.             break;
  47.         case 's' :
  48.             $second oGetopt::$optarg;
  49.             break;
  50.         case 't' :
  51.             $third true;
  52.             break;
  53.         default :
  54.             exit (1);
  55.     }
  56. }
  57.  
  58.  
  59. echo "Result:\n";
  60. echo "  Option f (value )  => $first\n";
  61. echo "  Option s (value )  => $second\n";
  62. echo "  Option t (flag  )  => $third\n";
  63. echo "  Number of \$optcmd => " oGetopt::$optcno "\n";
  64. echo "Print_r (oGetopt::\$optcmd):\n";
  65. print_r (oGetopt::$optcmd);
  66.  
  67. echo "\n\n";
  68.  
  69. $getopt new oGetopt;
  70. # Initialized getopt order variables
  71. #$getopt->init ();
  72.  
  73. oGetopt::$longopt = (object) array (
  74.     'first'  => 'f',
  75.     'second' => 's',
  76.     'third'  => 't',
  77. );
  78.  
  79. $first false;
  80. $third false;
  81. while ( ($opt $getopt->exec ($argc$argv"fs:t:")) !== false {
  82.     switch $opt {
  83.         case 'f' :
  84.             $first true;
  85.             break;
  86.         case 's' :
  87.             $second oGetopt::$optarg;
  88.             break;
  89.         case 't' :
  90.             $third oGetopt::$optarg;
  91.             break;
  92.         default :
  93.             exit (1);
  94.     }
  95. }
  96.  
  97.  
  98. echo "Result:\n";
  99. echo "  Option f (flag  )  => $first\n";
  100. echo "  Option s (value )  => $second\n";
  101. echo "  Option t (value )  => $third\n";
  102. echo "  Number of \$optcmd => " oGetopt::$optcno "\n";
  103. echo "Print_r (oGetopt::\$optcmd):\n";
  104. print_r (oGetopt::$optcmd);
  105.  
  106. echo "#############################################################\n";
  107. echo "\n";
  108. ?>

Documentation generated on Tue, 14 May 2019 02:00:42 +0900 by phpDocumentor 1.4.4