PHP/CLI

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP
Revision as of 16:34, 29 September 2023 by Woozle (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Although PHP is most commonly used to write web applications, it can also be used for scripts that run from a command line interface (CLI). The CLI environment is a little different than the web environment, and PHP's current documentation doesn't make it easy to locate the relevant pieces.

Arguments

Predefined variables:

  • $argc contains the number of arguments passed to the current script
  • $argv[] contains an array of all the arguments passed to the script
    • $argv[0] is always the name that was used to run the script.

Note that these variables are only present in the global scope; to use them inside of objects, they will need to be passed in somehow.

Other:

See also file/glob for interfacing with the CLI environment's file-globbing services

Interactivity

Links