Index of: /package/oGetopt/

File Name  ↓ File Size  ↓ Date  ↓ 
--
336 B2016-Jan-07 06:28
2.4 KiB2009-Aug-08 07:55
2.8 KiB2014-Jan-25 18:27
2.8 KiB2012-Oct-14 22:33
2.8 KiB2016-Jan-07 06:25

oGetopt pear package

OOPS C library의 o_getopt wrapping Class로서 glibc의 getopt 보다 조금더 직관적인 대안을 제시 합니다.

Reference: Example:
<?php
require_once "oGetopt.php";
 
echo "#############################################################\n";
echo "Command Lines:\n    ";
foreach ( $argv as $v ) {
    echo "$v ";
}
echo "\n\n";
 
# Initialized getopt order variables
oGetopt::init ();
 
oGetopt::$longopt = (object) array (
    'first'  => 'f',
    'second' => 's',
    'third'  => 't',
);
 
$first = false;
$third = false;
while ( ($opt = oGetopt::exec ($argc, $argv, "f:s:t")) !== false ) {
    switch ( $opt ) {
        case 'f' :
            $first = oGetopt::$optarg;
            break;
        case 's' :
            $second = oGetopt::$optarg;
            break;
        case 't' :
            $third = true;
            break;
        default :
            exit (1);
    }
}
 
 
echo "Result:\n";
echo "  Option f (value )  => $first\n";
echo "  Option s (value )  => $second\n";
echo "  Option t (flag  )  => $third\n";
echo "  Number of \$optcmd => " . oGetopt::$optcno . "\n";
echo "Print_r (oGetopt::\$optcmd):\n";
print_r (oGetopt::$optcmd);
 
echo "\n\n";
 
$getopt = new oGetopt;
# Initialized getopt order variables
#$getopt->init ();
 
oGetopt::$longopt = (object) array (
    'first'  => 'f',
    'second' => 's',
    'third'  => 't',
);
 
$first = false;
$third = false;
while ( ($opt = $getopt->exec ($argc, $argv, "fs:t:")) !== false ) {
    switch ( $opt ) {
        case 'f' :
            $first = true;
            break;
        case 's' :
            $second = oGetopt::$optarg;
            break;
        case 't' :
            $third = oGetopt::$optarg;
            break;
        default :
            exit (1);
    }
}
 
 
echo "Result:\n";
echo "  Option f (flag  )  => $first\n";
echo "  Option s (value )  => $second\n";
echo "  Option t (value )  => $third\n";
echo "  Number of \$optcmd => " . oGetopt::$optcno . "\n";
echo "Print_r (oGetopt::\$optcmd):\n";
print_r (oGetopt::$optcmd);
 
echo "#############################################################\n";
echo "\n";
?>
Installation:

이 패키지는 다른 패키지에 의존성이 있습니다. 그러므로 아래의 pear 명령을 이용하여 설치하는 것을 권장 합니다.

shell> pear channel-discover pear.oops.org
shell> pear install oops/oGetopt
shell> pear list -a