What does the "arguments" function written in PHP do?

Asked

Viewed 87 times

-4

Complete code

function argumentos($argv, $campo) {
        $_ARG = array();
        foreach ($argv as $arg) {
            if (ereg('--[a-zA-Z0-9]*=.*', $arg)) {
                $str = split("=", $arg);
                $arg = '';
                $key = ereg_replace("--", '', $str[0]);
                for ($i = 1; $i < count($str); $i++) {
                    $arg .= $str[$i];
                }
                $_ARG[$key] = $arg;
            } elseif (ereg('-[a-zA-Z0-9]', $arg)) {
                $arg = ereg_replace("-", '', $arg);
                $_ARG[$arg] = 'true';
            }
        }
        return $_ARG[$campo];
    }

What is the functionality of this function?

  • Take a tour to understand the stackoverflow site: http://answall.com/tour

1 answer

3


It separates and validates arguments coming, probably from the command line, and returns one of them specifically. It seems the arguments exist in two forms: key pairs and value separated by a = after a --; and simple names started by - that only need to exist.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.