📄 features.commandline.html
字号:
<br /> </p></blockquote> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-v</td> <td colspan="1" rowspan="1" align="left">--version</td> <td colspan="1" rowspan="1" align="left"> <p class="para"><div class="informalexample"> <p class="para"> Writes the PHP, PHP SAPI, and Zend version to standard output, e.g. </p> <div class="example-contents"><pre><div class="cdata"><pre>$ php -vPHP 4.3.0 (cli), Copyright (c) 1997-2002 The PHP GroupZend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies</pre></div> </pre></div> </div></p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-w</td> <td colspan="1" rowspan="1" align="left">--strip</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Display source with stripped comments and whitespace. </p> <blockquote><p><b class="note">Note</b>: This option does not work together with the <span class="option">-r</span> option. <br /> </p></blockquote> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-z</td> <td colspan="1" rowspan="1" align="left">--zend-extension</td> <td colspan="1" rowspan="1" align="left"> <p class="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 <var class="filename">/etc/ld.so.conf</var> 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. </p> </td> </tr> <tr valign="middle"> <td class="empty"> </td> <td colspan="1" rowspan="1" align="left">--ini</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Shows configuration file names and scanned directories. Available as of PHP 5.2.3. <div class="example"> <p><b>Example #3 <i>--ini</i> example</b></p> <div class="example-contents"><div class="cdata"><pre>$ php --iniConfiguration File (php.ini) Path: /usr/dev/php/5.2/libLoaded Configuration File: /usr/dev/php/5.2/lib/php.iniScan for additional .ini files in: (none)Additional .ini files parsed: (none)</pre></div> </div> </div> </p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">--rf</td> <td colspan="1" rowspan="1" align="left">--rfunction</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Shows information about the given function or class method (e.g. number and name of the parameters). Available as of PHP 5.1.2. </p> <p class="para"> This option is only available if PHP was compiled with <a href="language.oop5.reflection.html" class="link">Reflection</a> support. </p> <p class="para"> <div class="example"> <p><b>Example #4 basic <i>--rf</i> usage</b></p> <div class="example-contents"><div class="cdata"><pre>$ php --rf var_dumpFunction [ <internal> public function var_dump ] { - Parameters [2] { Parameter #0 [ <required> $var ] Parameter #1 [ <optional> $... ] }}</pre></div> </div> </div> </p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">--rc</td> <td colspan="1" rowspan="1" align="left">--rclass</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Show information about the given class (list of constants, properties and methods). Available as of PHP 5.1.2. </p> <p class="para"> This option is only available if PHP was compiled with <a href="language.oop5.reflection.html" class="link">Reflection</a> support. </p> <p class="para"> <div class="example"> <p><b>Example #5 <i>--rc</i> example</b></p> <div class="example-contents"><div class="cdata"><pre>$ php --rc DirectoryClass [ <internal:standard> class Directory ] { - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [3] { Method [ <internal> public method close ] { } Method [ <internal> public method rewind ] { } Method [ <internal> public method read ] { } }}</pre></div> </div> </div> </p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">--re</td> <td colspan="1" rowspan="1" align="left">--rextension</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Show information about the given extension (list of <var class="filename">php.ini</var> options, defined functions, constants and classes). Available as of PHP 5.1.2. </p> <p class="para"> This option is only available if PHP was compiled with <a href="language.oop5.reflection.html" class="link">Reflection</a> support. </p> <p class="para"> <div class="example"> <p><b>Example #6 <i>--re</i> example</b></p> <div class="example-contents"><div class="cdata"><pre>$ php --re jsonExtension [ <persistent> extension #19 json version 1.2.1 ] { - Functions { Function [ <internal> function json_encode ] { } Function [ <internal> function json_decode ] { } }}</pre></div> </div> </div> </p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">--ri</td> <td colspan="1" rowspan="1" align="left">--rextinfo</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Shows the configuration information for the given extension (the same information that is returned by <a href="function.phpinfo.html" class="function">phpinfo()</a>). Available as of PHP 5.2.2. The core configuration information are available using "main" as extension name. </p> <p class="para"> <div class="example"> <p><b>Example #7 <i>--ri</i> example</b></p> <div class="example-contents"><div class="cdata"><pre>$ php --ri datedatedate/time support => enabled"Olson" Timezone Database Version => 2007.5Timezone Database => internalDefault timezone => Europe/OsloDirective => Local Value => Master Valuedate.timezone => Europe/Oslo => Europe/Oslodate.default_latitude => 59.22482 => 59.22482date.default_longitude => 11.018084 => 11.018084date.sunset_zenith => 90.583333 => 90.583333date.sunrise_zenith => 90.583333 => 90.583333</pre></div> </div> </div> </p> </td> </tr> </tbody> </colgroup> </table> </p> <p class="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 <var class="filename">php.exe</var> with the double click option of the <i>.php</i> 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. </p> <p class="para"> <div class="example"> <p><b>Example #8 Script intended to be run from command line (script.php)</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000">#!/usr/bin/php<br /><span style="color: #0000BB"><?php<br /><br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$argc </span><span style="color: #007700">!= </span><span style="color: #0000BB">2 </span><span style="color: #007700">|| </span><span style="color: #0000BB">in_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$argv</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">], array(</span><span style="color: #DD0000">'--help'</span><span style="color: #007700">, </span><span style="color: #DD0000">'-help'</span><span style="color: #007700">, </span><span style="color: #DD0000">'-h'</span><span style="color: #007700">, </span><span style="color: #DD0000">'-?'</span><span style="color: #007700">))) {<br /></span><span style="color: #0000BB">?><br /></span><br />This is a command line PHP script with one option.<br /><br /> Usage:<br /> <span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$argv</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]; </span><span style="color: #0000BB">?></span> <option><br /><br /> <option> can be some word you would like<br /> to print out. With the --help, -help, -h,<br /> or -? options, you can get this help.<br /><br /><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">} else {<br /> echo </span><span style="color: #0000BB">$argv</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">];<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="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 HTTP header printouts. There are two variables you can use while writing command line applications with PHP: <var class="varname"><a href="reserved.variables.argc.html" class="classname">$argc</a></var> and <var class="varname"><a href="reserved.variables.argv.html" class="classname">$argv</a></var>. 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 (<var class="varname"><a href="reserved.variables.argv.html" class="classname">$argv[0]</a></var>). </p> <p class="para"> In the program above we checked if there are less or more than one arguments. Also if the argument was <span class="option">--help</span>, <span class="option">-help</span>, <span class="option">-h</span> or <span class="option">-?</span>, we printed out the help message, printing the script name dynamically. If we received some other argument we echoed that out. </p> <p class="para"> If you would like to run the above script on Unix, you need to make it executable, and simply call it as <strong class="command">script.php echothis</strong> or <strong class="command">script.php -h</strong>. On Windows, you can make a batch file for this task: </p> <p class="para"> <div class="example"> <p><b>Example #9 Batch file to run a command line PHP script (script.bat)</b></p> <div class="example-contents"><div class="cdata"><pre>@C:\php\php.exe script.php %1 %2 %3 %4</pre></div> </div> </div> </p> <p class="para"> Assuming you named the above program <var class="filename">script.php</var>, and you have your CLI <var class="filename">php.exe</var> in <var class="filename">C:\php\php.exe</var> this batch file will run it for you with your added options: <strong class="command">script.bat echothis</strong> or <strong class="command">script.bat -h</strong>. </p> <p class="para"> See also the <a href="ref.readline.html" class="link">Readline</a> extension documentation for more functions you can use to enhance your command line applications in PHP. </p></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.html">Features</a></div> <div class="next" style="text-align: right; float: right;"><a href="funcref.html">Function Reference</a></div> <div class="up"><a href="features.html">Features</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -