Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

Tutorial PHP - Working with PHP CLI
 

Developing applications designed to run from a terminal instead of through a Web browser requires us, as developers, to look a bit differently at the way scripts are written. For instance, when developing shell scripts in PHP, you do not need to be concerned with things such as sessions (the "stateless" protocol problem does not apply to client-side scripts). However, new problems arise when you attempt to design scripts that require interaction with the user because we no longer can rely on the $_GET, $_POST, and $_COOKIE superglobals for input or HTML for output. Instead of these facilities, to interact with the user, your scripts must instead rely on CLI-specific extensions and third-party applications.


Command-Line Arguments and Return Codes

One of the first new ways of accepting input from the user in CLI scripts is to use command-line arguments. These arguments are passed to your scripts when they are executed and generally enable or define certain options. An example of a command-line argument is the -h argument passed to the PHP executable (which displayed a list of all available argumentssee the previous section). To receive a list of command-line arguments in PHP, you'll need to be familiar with two predefined variables: $argc and $argv. These two variables (abbreviations for argument count and argument values) store all the information passed to your scripts in the form of command-line arguments. As you may have already guessed, the $argc parameter is an integer count of the total number of arguments passed, and $argv is an integer array of the value(s) of those arguments in the order they were passed. Every CLI PHP script that is executed will always have at least one argument provided to it. This argument represents the filename of the script currently being executed.


Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Wallpaper 95
Statistic


Last Post

 
Top! Top!