mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
- minor improvements
# Nice work Markus! git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@81712 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
7745d6f840
commit
6509b7fc28
1 changed files with 25 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<chapter id="features.commandline">
|
||||
<title>Using PHP from the command line</title>
|
||||
<!-- NEW DOCUMENTATION STARTS -->
|
||||
|
@ -148,7 +148,7 @@ $ php -f another_directory/test.php
|
|||
/tmp
|
||||
]]>
|
||||
</screen>
|
||||
This allows for greater flexibility when writing shell tools in
|
||||
This allows greater flexibility when writing shell tools in
|
||||
<literal>PHP</literal>.
|
||||
</para>
|
||||
<note>
|
||||
|
@ -229,7 +229,7 @@ php -r 'print_r(get_defined_constants());'
|
|||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Read the example carefully, thera are no beginning or end tags! The
|
||||
Read the example carefully, thera are no beginning or ending tags! The
|
||||
<literal>-r</literal> switch simply does not need them. Using them will
|
||||
lead to a parser error.
|
||||
</para>
|
||||
|
@ -237,7 +237,7 @@ php -r 'print_r(get_defined_constants());'
|
|||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Provide the <literal>PHP</literal> code to execute via standard input
|
||||
Provide the <literal>PHP</literal> code to execute via standard input
|
||||
(<literal>stdin</literal>).
|
||||
</para>
|
||||
<para>
|
||||
|
@ -259,7 +259,7 @@ $ some_application | some_filter | php | sort -u >final_output.txt
|
|||
accepts a number of arguments but also your <literal>PHP</literal> script
|
||||
can receive them. The number of arguments which can be passed to your script
|
||||
is not limited by <literal>PHP</literal> (the shell has a certain size limit
|
||||
in numbers of characters which can be passed, usually you won't hit this
|
||||
in numbers 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 <literal>$argv</literal>. The zero index always contains the script
|
||||
name (which is <literal>-</literal> in case the <literal>PHP</literal> code
|
||||
|
@ -271,11 +271,11 @@ $ some_application | some_filter | php | sort -u >final_output.txt
|
|||
</para>
|
||||
<para>
|
||||
As long as the arguments you want to pass to your script do not start with
|
||||
the <literal>-</literal> character, there's nothing special to whatch out
|
||||
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 <literal>PHP</literal>
|
||||
thinks it has to handle it. To prevent this use the argument list separator
|
||||
<literal>--</literal>. After argument has been parsed by
|
||||
<literal>--</literal>. After the argument has been parsed by
|
||||
<literal>PHP</literal>, every argument following it is passed
|
||||
untoched/unparsed to your script.
|
||||
</para>
|
||||
|
@ -297,8 +297,8 @@ array(2) {
|
|||
]]>
|
||||
</screen>
|
||||
<para>
|
||||
But, there's another way of using <literal>PHP</literal> for shell
|
||||
scripting. You can write a script whose first line starts with
|
||||
However, there's another way of using <literal>PHP</literal> for shell
|
||||
scripting. You can write a script which's first line starts with
|
||||
<literal>#!/usr/bin/php</literal> and then following the normal
|
||||
<literal>PHP</literal> code included within the <literal>PHP</literal>
|
||||
starting and end tags and set the execution attributes of the file
|
||||
|
@ -393,11 +393,13 @@ array(4) {
|
|||
<entry>-v</entry>
|
||||
<entry>
|
||||
<para>
|
||||
Writes the PHP and Zend version to standard output, e.g.
|
||||
Writes the PHP, PHP SAPI, and Zend version to standard output, e.g.
|
||||
<screen>
|
||||
<![CDATA[
|
||||
$ php -v
|
||||
PHP 4.3.0-dev (cli)
|
||||
Zend Engine v1.2.1, Copyright (c) 1998-2002 Zend Technologies
|
||||
]]>
|
||||
</screen>
|
||||
</para>
|
||||
</entry>
|
||||
|
@ -410,9 +412,11 @@ Zend Engine v1.2.1, Copyright (c) 1998-2002 Zend Technologies
|
|||
&php.ini; or you can specify a custom <literal>INI</literal> file
|
||||
directly (which does not need to be named &php.ini;), e.g.:
|
||||
<screen>
|
||||
<![CDATA[
|
||||
$ php -c /custom/directory/ my_script.php
|
||||
|
||||
$ php -c /custom/directory/custom-file.ini my_script.php
|
||||
]]>
|
||||
</screen>
|
||||
</para>
|
||||
</entry>
|
||||
|
@ -481,9 +485,9 @@ string(15) "doesntmakesense"
|
|||
<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 Unix
|
||||
(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
|
||||
not use the systems library search path. A relative filename with a
|
||||
directory information will tell <literal>PHP</literal> only to try to
|
||||
load the extension relative to the current directory.
|
||||
</para>
|
||||
|
@ -521,6 +525,7 @@ string(15) "doesntmakesense"
|
|||
Using this option, PHP prints out the built in (and loaded) PHP and
|
||||
Zend modules:
|
||||
<screen>
|
||||
<![CDATA[
|
||||
$ php -m
|
||||
[PHP Modules]
|
||||
xml
|
||||
|
@ -535,7 +540,7 @@ mbstring
|
|||
ctype
|
||||
|
||||
[Zend Modules]
|
||||
|
||||
]]>
|
||||
</screen>
|
||||
</para>
|
||||
</entry>
|
||||
|
@ -575,7 +580,7 @@ $ php -r "$foo = get_defined_constants();"
|
|||
Command line code(1) : Parse error - parse error, unexpected '='
|
||||
]]>
|
||||
</screen>
|
||||
The problem here is that the shell performs variable substritution
|
||||
The problem here is that the sh/bash performs variable substritution
|
||||
even when using double quotes <literal>"</literal>. Since the
|
||||
variable <literal>$foo</literal> is unlikely to be defined, it
|
||||
expands to nothing which results in being the code passed to
|
||||
|
@ -586,8 +591,8 @@ $ php -r " = get_defined_constants();"
|
|||
]]>
|
||||
</screen>
|
||||
The correct way would be to use single quotes <literal>'</literal>.
|
||||
The shell doesn't expand variables in strings quoted with single
|
||||
quotes:
|
||||
variables in strings quoted with single quotes are not expanded
|
||||
by sh/bash.
|
||||
<screen>
|
||||
<![CDATA[
|
||||
$ php -r '$foo = get_defined_constants(); var_dump($foo);'
|
||||
|
@ -604,6 +609,10 @@ array(370) {
|
|||
[...]
|
||||
]]>
|
||||
</screen>
|
||||
If you are using a shell different from sh/bash, you might experience
|
||||
further issues. Feel free to open a bug report or send a mail to
|
||||
phpdoc@lists.php.net.
|
||||
|
||||
One still can easily run intro troubles when trying to get shell
|
||||
variables into the code or using backslashes for escaping. You've
|
||||
been warned. <!-- :-) -->
|
||||
|
|
Loading…
Reference in a new issue