mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
Improvify and simplicate English; convert from second to third person; make tenses more consistent.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@313007 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
32f16f66c3
commit
70b2e0026b
1 changed files with 157 additions and 161 deletions
|
@ -78,7 +78,7 @@
|
|||
<note>
|
||||
<para>
|
||||
A Unix <literal>man</literal>ual page is available by typing <command>man
|
||||
php</command> in your shell environment.
|
||||
php</command> in the shell environment.
|
||||
</para>
|
||||
</note>
|
||||
</section>
|
||||
|
@ -105,7 +105,7 @@
|
|||
<para>
|
||||
&cli; is started up in quiet mode by default, though the <option>-q</option>
|
||||
and <option>--no-header</option> switches are kept for compatibility so
|
||||
that you can use older <acronym>CGI</acronym> scripts.
|
||||
that it is possible to use older <acronym>CGI</acronym> scripts.
|
||||
</para>
|
||||
<para>
|
||||
It does not change the working directory to that of the script.
|
||||
|
@ -138,19 +138,20 @@
|
|||
<entry><link linkend="ini.html-errors">html_errors</link></entry>
|
||||
<entry>&false;</entry>
|
||||
<entry>
|
||||
It can be quite hard to read the error message in your shell when
|
||||
it's cluttered with all those meaningless <acronym>HTML</acronym>
|
||||
tags, therefore this directive defaults to &false;.
|
||||
Defaults to &false;, as it can be quite hard to read error messages
|
||||
in the shell enviroment when they are cluttered up with uninterpreted
|
||||
<acronym>HTML</acronym> tags.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><link linkend="ini.implicit-flush">implicit_flush</link></entry>
|
||||
<entry>&true;</entry>
|
||||
<entry>
|
||||
It is desired that any output coming from <function>print</function>,
|
||||
<function>echo</function> and friends is immediately written to the
|
||||
output and not cached in any buffer. You still can use
|
||||
<link linkend="ref.outcontrol">output buffering</link> if you want to
|
||||
In a shell environment, it is usually desirable for output, such as
|
||||
from <function>print</function>, <function>echo</function> and
|
||||
friends, to be displayed immediately, and not held in a buffer.
|
||||
Nonetheless, it is still possible to use
|
||||
<link linkend="ref.outcontrol">output buffering</link> to
|
||||
defer or manipulate standard output.
|
||||
</entry>
|
||||
</row>
|
||||
|
@ -158,10 +159,9 @@
|
|||
<entry><link linkend="ini.max-execution-time">max_execution_time</link></entry>
|
||||
<entry>0 (unlimited)</entry>
|
||||
<entry>
|
||||
Due to endless possibilities of using PHP in shell environments, the
|
||||
maximum execution time has been set to unlimited. Whereas
|
||||
applications written for the web are often executed very quickly,
|
||||
shell application tend to have a much longer execution time.
|
||||
PHP in a shell environment tends to be used for a much more diverse
|
||||
range of purposes than typical Web-based scripts, and as these can
|
||||
be very long-running, the maximum execution time is set to unlimited.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
|
@ -169,17 +169,18 @@
|
|||
<entry>&true;</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Because this setting is &true; you will always have access to
|
||||
<emphasis>argc</emphasis> (number of arguments passed to the
|
||||
Setting this to &true; means that scripts executed via the
|
||||
&cli; <acronym>SAPI</acronym> always have access to
|
||||
<emphasis>argc</emphasis> (number of arguments passed to the
|
||||
application) and <emphasis>argv</emphasis> (array of the actual
|
||||
arguments) in the &cli; <acronym>SAPI</acronym>.
|
||||
arguments).
|
||||
</para>
|
||||
<para>
|
||||
The PHP variables <varname>$argc</varname>
|
||||
and <varname>$argv</varname> are registered and filled in with the appropriate
|
||||
values when using the &cli; <acronym>SAPI</acronym>. You can also go
|
||||
through <varname>$_SERVER</varname> or. Example:
|
||||
<varname>$_SERVER['argv']</varname>
|
||||
and <varname>$argv</varname> are automatically set to the appropriate
|
||||
values when using the &cli; <acronym>SAPI</acronym>. These values can
|
||||
also be found in the <varname>$_SERVER</varname> array, for example:
|
||||
<varname>$_SERVER['argv']</varname>.
|
||||
</para>
|
||||
</entry>
|
||||
</row>
|
||||
|
@ -188,7 +189,7 @@
|
|||
<entry>&false;</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Although the &php.ini; setting is hardcoded to &false; the
|
||||
Although the &php.ini; setting is hardcoded to &false;, the
|
||||
<link linkend="book.outcontrol">Output buffering</link> functions
|
||||
are available.
|
||||
</para>
|
||||
|
@ -210,11 +211,11 @@
|
|||
<note>
|
||||
<para>
|
||||
These directives cannot be initialized with another value from the
|
||||
configuration file &php.ini; or a custom one (if specified). This is a
|
||||
limitation because those default values are applied after all
|
||||
configuration files have been parsed. However, their value can be changed
|
||||
during runtime (which does not make sense for all of those directives,
|
||||
e.g. <link linkend="ini.register-argc-argv">register_argc_argv</link>).
|
||||
configuration file &php.ini; or a custom one (if specified). This
|
||||
limitation is because the values are applied after all configuration
|
||||
files have been parsed. However, their values can be changed
|
||||
during runtime (although this is not sensible for all of them,
|
||||
such as <link linkend="ini.register-argc-argv">register_argc_argv</link>).
|
||||
</para>
|
||||
</note>
|
||||
<note>
|
||||
|
@ -222,7 +223,7 @@
|
|||
It is recommended to set
|
||||
<link linkend="ini.ignore-user-abort">ignore_user_abort</link> for
|
||||
command line scripts. See <function>ignore_user_abort</function> for
|
||||
more info.
|
||||
more information.
|
||||
</para>
|
||||
</note>
|
||||
</listitem>
|
||||
|
@ -238,7 +239,7 @@
|
|||
<listitem>
|
||||
<para>
|
||||
The &cli.sapi; does <emphasis role="strong">not</emphasis> change the
|
||||
current directory to the directory of the executed script!
|
||||
current directory to the directory of the executed script.
|
||||
</para>
|
||||
<example>
|
||||
<title>
|
||||
|
@ -305,7 +306,7 @@ $ php -f another_directory/test.php
|
|||
|
||||
<para>
|
||||
The list of command line options provided by the PHP binary can be queried
|
||||
anytime by running PHP with the <option>-h</option> switch:
|
||||
at any time by running PHP with the <option>-h</option> switch:
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Usage: php [options] [-f] <file> [--] [args...]
|
||||
|
@ -367,7 +368,7 @@ Usage: php [options] [-f] <file> [--] [args...]
|
|||
<entry>--interactive</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Runs PHP interactively. For more information, see the <link
|
||||
Run PHP interactively. For more information, see the <link
|
||||
linkend="features.commandline.interactive">Interactive shell</link>
|
||||
section.
|
||||
</para>
|
||||
|
@ -417,8 +418,8 @@ Usage: php [options] [-f] <file> [--] [args...]
|
|||
<entry>--php-ini</entry>
|
||||
<entry>
|
||||
<para>
|
||||
This option can either specify a directory where to look for
|
||||
&php.ini; or specify a custom <literal>INI</literal> file
|
||||
Specifies either a directory in which to look for
|
||||
&php.ini;, or a custom <literal>INI</literal> file
|
||||
(which does not need to be named &php.ini;), e.g.:
|
||||
</para>
|
||||
<para><informalexample>
|
||||
|
@ -431,7 +432,7 @@ $ php -c /custom/directory/custom-file.ini my_script.php
|
|||
</screen>
|
||||
</informalexample></para>
|
||||
<para>
|
||||
If you don't specify this option, file is searched in
|
||||
If this option is not specified, &php.ini; is searched for in the
|
||||
<link linkend="configuration.file">default locations</link>.
|
||||
</para>
|
||||
</entry>
|
||||
|
@ -441,7 +442,7 @@ $ php -c /custom/directory/custom-file.ini my_script.php
|
|||
<entry>--no-php-ini</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Ignore &php.ini; at all.
|
||||
Ignore &php.ini; completely.
|
||||
</para>
|
||||
</entry>
|
||||
</row>
|
||||
|
@ -450,7 +451,7 @@ $ php -c /custom/directory/custom-file.ini my_script.php
|
|||
<entry>--define</entry>
|
||||
<entry>
|
||||
<para>
|
||||
This option allows you to set a custom value for any of the configuration
|
||||
Set a custom value for any of the configuration
|
||||
directives allowed in &php.ini;. The syntax is:
|
||||
<screen>
|
||||
<![CDATA[
|
||||
|
@ -499,14 +500,14 @@ string(15) "doesntmakesense"
|
|||
<entry>--file</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Parses and executes the given filename to the <option>-f</option>
|
||||
option. This switch is optional and can be left out. Only providing
|
||||
Parse and execute the specified file. The
|
||||
<option>-f</option> is optional and may be omitted - providing just
|
||||
the filename to execute is sufficient.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
To pass arguments to scripts the first argument needs to be
|
||||
<literal>--</literal>, otherwise PHP will interperate them as PHP
|
||||
To pass arguments to a script, the first argument must be
|
||||
<literal>--</literal>, otherwise PHP will interpret them as PHP
|
||||
options.
|
||||
</para>
|
||||
</note>
|
||||
|
@ -516,20 +517,20 @@ string(15) "doesntmakesense"
|
|||
<entry>-h and -?</entry>
|
||||
<entry>--help and --usage</entry>
|
||||
<entry>
|
||||
With this option, you can get information about the actual list of
|
||||
command line options and some one line descriptions about what they do.
|
||||
Output a list of
|
||||
command line options with one line descriptions of what they do.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>-i</entry>
|
||||
<entry>--info</entry>
|
||||
<entry>
|
||||
This command line option calls <function>phpinfo</function>, and prints
|
||||
out the results. If PHP is not working correctly, it is
|
||||
advisable to use <command>php -i</command> and see whether any error
|
||||
Calls <function>phpinfo</function>, and prints out the results.
|
||||
If PHP is not working correctly, it is advisable to use the command
|
||||
<command>php -i</command> and see whether any error
|
||||
messages are printed out before or in place of the information tables.
|
||||
Beware that when using the <acronym>CGI</acronym> mode the output is in
|
||||
<acronym>HTML</acronym> and therefore quite huge.
|
||||
<acronym>HTML</acronym> and therefore very large.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
|
@ -537,7 +538,7 @@ string(15) "doesntmakesense"
|
|||
<entry>--syntax-check</entry>
|
||||
<entry>
|
||||
<para>
|
||||
This option provides a convenient way to only perform a syntax check
|
||||
Provides a convenient way to perform only a syntax check
|
||||
on the given PHP code. On success, the text
|
||||
<literal>No syntax errors detected in <filename></literal> is
|
||||
written to standard output and the shell return code is
|
||||
|
@ -548,7 +549,7 @@ string(15) "doesntmakesense"
|
|||
</para>
|
||||
<para>
|
||||
This option won't find fatal errors (like undefined functions). Use
|
||||
<option>-f</option> if you would like to test for fatal errors too.
|
||||
the <option>-f</option> to test for fatal errors too.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
|
@ -590,16 +591,15 @@ ctype
|
|||
<entry>--run</entry>
|
||||
<entry>
|
||||
<para>
|
||||
This option allows execution of PHP right from
|
||||
within the command line. The PHP start and end tags
|
||||
(<literal><?php</literal> and <literal>?></literal>) are
|
||||
<emphasis role="strong">not needed</emphasis> and will cause a parser
|
||||
error if present.
|
||||
Allows execution of PHP included directly on the command line.
|
||||
The PHP start and end tags (<literal><?php</literal> and
|
||||
<literal>?></literal>) are <emphasis role="strong">not
|
||||
needed</emphasis> and will cause a parse error if present.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Care has to be taken when using this form of PHP
|
||||
to not collide with command line variable substitution done by the
|
||||
Care must be taken when using this form of PHP not
|
||||
to collide with command line variable substitution done by the
|
||||
shell.
|
||||
</para>
|
||||
<example>
|
||||
|
@ -614,7 +614,7 @@ Parse error: syntax error, unexpected '=' in Command line code on line 1
|
|||
</screen>
|
||||
</example>
|
||||
<para>
|
||||
The problem here is that the sh/bash performs variable substitution
|
||||
The problem here is that sh/bash performs variable substitution
|
||||
even when using double quotes <literal>"</literal>. Since the
|
||||
variable <varname>$foo</varname> is unlikely to be defined, it
|
||||
expands to nothing which results in the code passed to
|
||||
|
@ -654,24 +654,24 @@ array(370) {
|
|||
</screen>
|
||||
</example>
|
||||
<para>
|
||||
If you are using a shell different from sh/bash, you might experience
|
||||
further issues. Feel free to open a bug report at
|
||||
If using a shell other than sh/bash, further issues might be
|
||||
experienced - if appropriate, a bug report should be opened at
|
||||
<link xlink:href="&url.php.bugs;">&url.php.bugs;</link>.
|
||||
One can still easily run into troubles when trying to get shell
|
||||
variables into the code or using backslashes for escaping. You've
|
||||
been warned.
|
||||
It is still easy to run into trouble when trying to use variables
|
||||
(shell or PHP) in commnad-line code, or using backslashes for
|
||||
escaping, so take great care when doing so. You have been warned!
|
||||
</para>
|
||||
</note>
|
||||
<note>
|
||||
<para>
|
||||
<option>-r</option> is available in the &cli.sapi; and not in the
|
||||
<option>-r</option> is available in the &cli.sapi;, but not in the
|
||||
<emphasis>CGI</emphasis> <acronym>SAPI</acronym>.
|
||||
</para>
|
||||
</note>
|
||||
<note>
|
||||
<para>
|
||||
This option is meant for a very basic stuff. Thus some configuration
|
||||
directives (e.g. <link
|
||||
This option is only intended for very basic code, so some
|
||||
configuration directives (such as <link
|
||||
linkend="ini.auto-prepend-file">auto_prepend_file</link> and <link
|
||||
linkend="ini.auto-append-file">auto_append_file</link>) are ignored
|
||||
in this mode.
|
||||
|
@ -742,9 +742,9 @@ Total Lines: 37328
|
|||
Display colour syntax highlighted source.
|
||||
</para>
|
||||
<para>
|
||||
This option uses the internal mechanism to parse the file and produces
|
||||
a HTML highlighted version of it and writes it to
|
||||
standard output. Note that all it does it to generate a block of
|
||||
This option uses the internal mechanism to parse the file and writes
|
||||
an HTML highlighted version of it to
|
||||
standard output. Note that all it does is generate a block of
|
||||
<literal><code> [...] </code></literal>
|
||||
HTML tags, no HTML headers.
|
||||
</para>
|
||||
|
@ -766,7 +766,7 @@ Total Lines: 37328
|
|||
<screen>
|
||||
<![CDATA[
|
||||
$ php -v
|
||||
PHP 5.3.1 (cli) (built: Dec 11 2009 19:55:07)
|
||||
PHP 5.3.1 (cli) (built: Dec 11 2009 19:55:07)
|
||||
Copyright (c) 1997-2009 The PHP Group
|
||||
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
|
||||
]]>
|
||||
|
@ -779,7 +779,7 @@ Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
|
|||
<entry>--strip</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Display source with stripped comments and whitespace.
|
||||
Display source with comments and whitespace stripped.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
|
@ -796,11 +796,11 @@ Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
|
|||
<para>
|
||||
Load Zend extension. If only a filename is given, PHP tries to load
|
||||
this extension from the current default library path on your system
|
||||
(usually specified <filename>/etc/ld.so.conf</filename> on Linux
|
||||
systems). Passing a filename with an absolute path information will
|
||||
not use the systems library search path. A relative filename with a
|
||||
directory information will tell PHP only to try to
|
||||
load the extension relative to the current directory.
|
||||
(usually <filename>/etc/ld.so.conf</filename> on Linux systems, for
|
||||
example). Passing a filename with an absolute path will
|
||||
not use the system's library search path. A relative filename including
|
||||
directory information will tell PHP to try
|
||||
loading the extension relative to the current directory.
|
||||
</para>
|
||||
</entry>
|
||||
</row>
|
||||
|
@ -809,7 +809,7 @@ Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
|
|||
<entry>--ini</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Shows configuration file names and scanned directories. Available as
|
||||
Show configuration file names and scanned directories. Available as
|
||||
of PHP 5.2.3.
|
||||
<example>
|
||||
<title><literal>--ini</literal> example</title>
|
||||
|
@ -831,7 +831,7 @@ Additional .ini files parsed: (none)
|
|||
<entry>--rfunction</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Shows information about the given function or class method (e.g.
|
||||
Show information about the given function or class method (e.g.
|
||||
number and name of the parameters). Available as of PHP 5.1.2.
|
||||
</para>
|
||||
<para>
|
||||
|
@ -944,7 +944,7 @@ Extension [ <persistent> extension #19 json version 1.2.1 ] {
|
|||
<entry>--rzendextension</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Shows the configuration information for the given Zend extension (the
|
||||
Show the configuration information for the given Zend extension (the
|
||||
same information that is returned by <function>phpinfo</function>).
|
||||
Available as of PHP 5.4.0.
|
||||
</para>
|
||||
|
@ -955,10 +955,10 @@ Extension [ <persistent> extension #19 json version 1.2.1 ] {
|
|||
<entry>--rextinfo</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Shows the configuration information for the given extension (the same
|
||||
Show the configuration information for the given extension (the same
|
||||
information that is returned by <function>phpinfo</function>).
|
||||
Available as of PHP 5.2.2. The core configuration information
|
||||
are available using "main" as extension name.
|
||||
is available using "main" as extension name.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
|
@ -1006,12 +1006,12 @@ date.sunrise_zenith => 90.583333 => 90.583333
|
|||
<titleabbrev>Usage</titleabbrev>
|
||||
|
||||
<para>
|
||||
The &cli.sapi; has three different ways of getting the PHP code you want to
|
||||
execute:
|
||||
There are three different ways of supplying the &cli.sapi; with PHP code
|
||||
to be executed:
|
||||
<orderedlist>
|
||||
<listitem>
|
||||
<para>
|
||||
Telling PHP to execute a certain file.
|
||||
Tell PHP to execute a certain file.
|
||||
</para>
|
||||
<informalexample>
|
||||
<screen>
|
||||
|
@ -1024,16 +1024,14 @@ $ php -f my_script.php
|
|||
</informalexample>
|
||||
<para>
|
||||
Both ways (whether using the <option>-f</option> switch or not) execute
|
||||
the file <filename>my_script.php</filename>. You can choose any file to
|
||||
execute, and your PHP scripts do not have to end with the
|
||||
<literal>.php</literal> extension but can have any name or extension
|
||||
you wish.
|
||||
the file <filename>my_script.php</filename>. Note that there is no
|
||||
restriction on which files can be executed; in particular, the filename
|
||||
is not required have a <literal>.php</literal> extension.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
If you need to pass arguments to your scripts you need to pass
|
||||
<literal>--</literal> as the first argument when using the
|
||||
<option>-f</option> switch.
|
||||
If arguments need to be passed to the script when using
|
||||
<option>-f</option>, the first argument must be <literal>--</literal>.
|
||||
</para>
|
||||
</note>
|
||||
</listitem>
|
||||
|
@ -1049,14 +1047,14 @@ $ php -r 'print_r(get_defined_constants());'
|
|||
</screen>
|
||||
</informalexample>
|
||||
<para>
|
||||
Special care has to be taken in regards of shell variable substitution and
|
||||
quoting usage.
|
||||
Special care has to be taken with regard to shell variable substitution and
|
||||
usage of quotes.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Read the example carefully, there are no beginning or ending tags! The
|
||||
<option>-r</option> switch simply does not need them. Using them will
|
||||
lead to a parser error.
|
||||
Read the example carefully: there are no beginning or ending tags! The
|
||||
<option>-r</option> switch simply does not need them, and using them will
|
||||
lead to a parse error.
|
||||
</para>
|
||||
</note>
|
||||
</listitem>
|
||||
|
@ -1066,7 +1064,7 @@ $ php -r 'print_r(get_defined_constants());'
|
|||
(<literal>stdin</literal>).
|
||||
</para>
|
||||
<para>
|
||||
This gives the powerful ability to dynamically create PHP code and feed it
|
||||
This gives the powerful ability to create PHP code dynamically and feed it
|
||||
to the binary, as shown in this (fictional) example:
|
||||
</para>
|
||||
<informalexample>
|
||||
|
@ -1082,33 +1080,34 @@ $ some_application | some_filter | php | sort -u > final_output.txt
|
|||
</para>
|
||||
|
||||
<para>
|
||||
Like every shell application, the PHP binary accepts a number of arguments
|
||||
but your PHP script can also receive arguments. The number of arguments which
|
||||
can be passed to your script is not limited by PHP (the shell has a certain
|
||||
size limit in the number of characters which can be passed; usually you won't
|
||||
hit this limit). The arguments passed to your script are available in the
|
||||
global array <varname>$argv</varname>. The first index (zero) always contains the
|
||||
name of the script as called from the command line. Note that, if the code is
|
||||
executed in-line using the command line switch <option>-r</option>, the value of
|
||||
<varname>$argv[0]</varname> will be simply a dash (<literal>-</literal>). The
|
||||
same is true if the code is executed via a pipe from <literal>STDIN</literal>.
|
||||
As with every shell application, the PHP binary accepts a number of
|
||||
arguments; however, the PHP script can also receive further arguments. The
|
||||
number of arguments that can be passed to your script is not limited by PHP
|
||||
(and although the shell has a limit to the number of characters which can be
|
||||
passed, this is not in general likely to be hit). The arguments passed to
|
||||
the script are available in the global array <varname>$argv</varname>. The
|
||||
first index (zero) always contains the name of the script as called from the
|
||||
command line. Note that, if the code is executed in-line using the command
|
||||
line switch <option>-r</option>, the value of <varname>$argv[0]</varname>
|
||||
will be just a dash (<literal>-</literal>). The same is true if the code is
|
||||
executed via a pipe from <literal>STDIN</literal>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The second registered global variable is <varname>$argc</varname> which
|
||||
A second global variable, <varname>$argc</varname>,
|
||||
contains the number of elements in the <varname>$argv</varname> array
|
||||
(<emphasis role="strong">not</emphasis> the number of arguments passed to the
|
||||
script).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
As long as the arguments you want to pass to your script do not start with
|
||||
As long as the arguments to be passed to the script do not start with
|
||||
the <literal>-</literal> character, there's nothing special to watch out for.
|
||||
Passing an argument to your script which starts with a <literal>-</literal>
|
||||
will cause trouble because PHP itself thinks it has to handle it. To prevent
|
||||
this, use the argument list separator <literal>--</literal>. After this
|
||||
separator has been parsed by PHP, every argument following it is passed
|
||||
untouched to your script.
|
||||
Passing an argument to the script which starts with a <literal>-</literal>
|
||||
will cause trouble because the PHP interpreter thinks it has to handle it
|
||||
itself, even before executing the script. To prevent this, use the argument
|
||||
list separator <literal>--</literal>. After this separator has been parsed by
|
||||
PHP, every following argument is passed untouched to the script.
|
||||
</para>
|
||||
|
||||
<informalexample>
|
||||
|
@ -1119,7 +1118,7 @@ $ php -r 'var_dump($argv);' -h
|
|||
Usage: php [options] [-f] <file> [args...]
|
||||
[...]
|
||||
|
||||
# This will pass the '-h' argument to your script and prevent PHP from showing it's usage
|
||||
# This will pass the '-h' argument to the script and prevent PHP from showing its usage
|
||||
$ php -r 'var_dump($argv);' -- -h
|
||||
array(2) {
|
||||
[0]=>
|
||||
|
@ -1132,13 +1131,13 @@ array(2) {
|
|||
</informalexample>
|
||||
|
||||
<para>
|
||||
However on Unix systems, there's another way of using PHP for shell
|
||||
scripting. You can write a script where the first line starts with
|
||||
<literal>#!/usr/bin/php</literal> (substitute with the path to your PHP &cli;
|
||||
binary if necessary. Following this you can place normal PHP code included
|
||||
within the PHP starting and end tags. Once you have set the execution
|
||||
attributes of the file appropriately (e.g. <command>chmod +x test</command>)
|
||||
your script can be executed like a normal shell or perl script:
|
||||
However, on Unix systems there's another way of using PHP for shell
|
||||
scripting: make the first line of the script start with
|
||||
<literal>#!/usr/bin/php</literal> (or whatever the path to your PHP &cli;
|
||||
binary is if different). The rest of the file should contain normal PHP code
|
||||
within the usual PHP starting and end tags. Once the execution attributes of
|
||||
the file are set appropriately (e.g. <command>chmod +x test</command>),
|
||||
the script can be executed like any other shell or perl script:
|
||||
</para>
|
||||
|
||||
<example>
|
||||
|
@ -1153,7 +1152,7 @@ var_dump($argv);
|
|||
</programlisting>
|
||||
<para>
|
||||
Assuming this file is named <filename>test</filename> in the current
|
||||
directory, we can now do the following:
|
||||
directory, it is now possible to do the following:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
|
@ -1174,21 +1173,21 @@ array(4) {
|
|||
</example>
|
||||
|
||||
<para>
|
||||
As you see, in this case no care needs to be taken when passing parameters
|
||||
which start with <literal>-</literal> to your script.
|
||||
As can be seen, in this case no special care needs to be taken when passing parameters
|
||||
starting with <literal>-</literal>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The PHP executable can be used to run PHP scripts absolutely independent
|
||||
from the web server. If you are on a Unix system, you should add a special
|
||||
first line to your PHP script, and make it executable, so the system will
|
||||
know, what program should run the script. On a Windows platform you can
|
||||
associate <filename>php.exe</filename> with the double click option of the
|
||||
<literal>.php</literal> files, or you can make a batch
|
||||
file to run the script through PHP. The first line added to the script to
|
||||
work on Unix won't hurt on Windows, so you can write cross platform programs
|
||||
this way. A simple example of writing a command line PHP program can be
|
||||
found below.
|
||||
The PHP executable can be used to run PHP scripts absolutely independent of
|
||||
the web server. On Unix systems, the special <literal>#!</literal> (or
|
||||
"shebang") first line should be added to PHP scripts so that the system can
|
||||
automatically tell which program should run the script. On Windows platforms,
|
||||
it's possible to associate <filename>php.exe</filename> with the double
|
||||
click option of the <literal>.php</literal> extension, or a batch file can
|
||||
be created to run scripts through PHP. The special shebang first line for
|
||||
Unix does no harm on Windows (as it's formatted as a PHP comment), so cross
|
||||
platform programs can be written by including it. A simple example of
|
||||
writing a command line PHP program is shown below.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -1222,29 +1221,26 @@ This is a command line PHP script with one option.
|
|||
</para>
|
||||
|
||||
<para>
|
||||
In the script above, we used the special first line to indicate that this
|
||||
file should be run by PHP. We work with a &cli; version here, so there will
|
||||
be no <acronym>HTTP</acronym> header printouts. There are two variables you
|
||||
can use while writing command line applications with PHP:
|
||||
<varname>$argc</varname> and <varname>$argv</varname>. The first is the
|
||||
number of arguments plus one (the name of the script running). The second is
|
||||
an array containing the arguments, starting with the script name as number
|
||||
zero (<varname>$argv[0]</varname>).
|
||||
The script above includes the Unix shebang first line to indicate that this
|
||||
file should be run by PHP. We are working with a &cli; version here, so
|
||||
no <acronym>HTTP</acronym> headers will be output.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
In the program above we checked if there are less or more than one arguments.
|
||||
Also if the argument was <option>--help</option>, <option>-help</option>,
|
||||
<option>-h</option> or <option>-?</option>, we printed out the help message,
|
||||
printing the script name dynamically. If we received some other argument we
|
||||
echoed that out.
|
||||
The program first checks that there is the required one argument (in
|
||||
addition to the script name, which is also counted). If not, or if the
|
||||
argument was <option>--help</option>, <option>-help</option>,
|
||||
<option>-h</option> or <option>-?</option>, the help message is printed out,
|
||||
using <varname>$argv[0]</varname> to dynamically print the script name as
|
||||
typed on the command line. Otherwise, the argument is echoed out exactly as
|
||||
received.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If you would like to run the above script on Unix, you need to make it
|
||||
executable, and simply call it as <command>script.php echothis</command> or
|
||||
<command>script.php -h</command>. On Windows, you can make a batch file for
|
||||
this task:
|
||||
To run the above script on Unix, it must be made
|
||||
executable, and called simply as <command>script.php echothis</command> or
|
||||
<command>script.php -h</command>. On Windows, a batch file similar to the
|
||||
following can be created for this task:
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -1260,20 +1256,20 @@ This is a command line PHP script with one option.
|
|||
</para>
|
||||
|
||||
<para>
|
||||
Assuming you named the above program <filename>script.php</filename>, and you
|
||||
have your &cli; <filename>php.exe</filename> in <filename>C:\php\php.exe
|
||||
</filename> this batch file will run it for you with your added options:
|
||||
Assuming the above program is named <filename>script.php</filename>, and the
|
||||
&cli; <filename>php.exe</filename> is in <filename>C:\php\php.exe</filename>,
|
||||
this batch file will run it, passing on all appended options:
|
||||
<command>script.bat echothis</command> or <command>script.bat -h</command>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
See also the <link linkend="ref.readline">Readline</link> extension
|
||||
documentation for more functions you can use to enhance your command line
|
||||
documentation for more functions which can be used to enhance command line
|
||||
applications in PHP.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If you are on Windows, PHP can be configured to run without the need to
|
||||
On Windows, PHP can be configured to run without the need to
|
||||
supply the <filename>C:\php\php.exe</filename> or the <literal>.php</literal>
|
||||
extension, as described in <link linkend="install.windows.commandline">Command
|
||||
Line PHP on Microsoft Windows</link>.
|
||||
|
@ -1399,7 +1395,7 @@ php -r 'fwrite(STDERR, "stderr\n");'
|
|||
</para>
|
||||
|
||||
<example>
|
||||
<title>Executing code using the interactive shell</title>
|
||||
<title>Executing code using the interactive shell</title>
|
||||
<programlisting role="shell">
|
||||
<![CDATA[
|
||||
$ php -a
|
||||
|
@ -1413,7 +1409,7 @@ php { return $n + 2;
|
|||
php { }
|
||||
php > var_dump(addtwo(2));
|
||||
int(4)
|
||||
php >
|
||||
php >
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -1447,8 +1443,8 @@ php > strpt[TAB]ime(
|
|||
]]>
|
||||
</programlisting>
|
||||
<simpara>
|
||||
It is also possible doing completion on things that have been defined
|
||||
during the interactive shell session:
|
||||
Completion will also work for names that have been defined
|
||||
during the current interactive shell session:
|
||||
</simpara>
|
||||
<programlisting role="shell">
|
||||
<![CDATA[
|
||||
|
@ -1459,14 +1455,14 @@ php > $foo[TAB]ThisIsAReallyLongVariableName
|
|||
</example>
|
||||
|
||||
<para>
|
||||
The interactive shell stores your history and can be accessed using the up
|
||||
The interactive shell stores your history which can be accessed using the up
|
||||
and down keys. The history is saved in the
|
||||
<filename>~/.php_history</filename> file.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
As of PHP 5.4.0, the &cli.sapi; provides
|
||||
two new &php.ini; settings: <parameter>cli.pager</parameter> and
|
||||
the &php.ini; settings <parameter>cli.pager</parameter> and
|
||||
<parameter>cli.prompt</parameter>. The <parameter>cli.pager</parameter>
|
||||
setting allows an external program (such as <filename>less</filename>) to
|
||||
act as a pager for the output instead of being displayed directly on the
|
||||
|
@ -1475,7 +1471,7 @@ php > $foo[TAB]ThisIsAReallyLongVariableName
|
|||
</para>
|
||||
|
||||
<para>
|
||||
In PHP 5.4.0 it was also made possible setting
|
||||
In PHP 5.4.0 it was also made possible to set
|
||||
&php.ini; settings in the interactive shell using a shorthand notation.
|
||||
</para>
|
||||
|
||||
|
|
Loading…
Reference in a new issue