📄 features.commandline.html
字号:
<tr valign="middle"> <td colspan="1" rowspan="1" align="left">-n</td> <td colspan="1" rowspan="1" align="left">--no-php-ini</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Ignore <var class="filename">php.ini</var> at all. This switch is available since PHP 4.3.0. </p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-d</td> <td colspan="1" rowspan="1" align="left">--define</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> This option allows you to set a custom value for any of the configuration directives allowed in <var class="filename">php.ini</var>. The syntax is: <div class="example-contents"><pre><div class="cdata"><pre>-d configuration_directive[=value]</pre></div> </pre></div> </p> <p class="para"><div class="informalexample"> <p class="para"> Examples (lines are wrapped for layout reasons): </p> <div class="example-contents"><pre><div class="cdata"><pre># Omitting the value part will set the given configuration directive to "1"$ php -d max_execution_time -r '$foo = ini_get("max_execution_time"); var_dump($foo);'string(1) "1"# Passing an empty value part will set the configuration directive to ""php -d max_execution_time= -r '$foo = ini_get("max_execution_time"); var_dump($foo);'string(0) ""# The configuration directive will be set to anything passed after the '=' character$ php -d max_execution_time=20 -r '$foo = ini_get("max_execution_time"); var_dump($foo);'string(2) "20"$ php -d max_execution_time=doesntmakesense -r '$foo = ini_get("max_execution_time"); var_dump($foo);'string(15) "doesntmakesense"</pre></div> </pre></div> </div></p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-e</td> <td colspan="1" rowspan="1" align="left">--profile-info</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Activate the extended information mode, to be used by a debugger/profiler. </p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-f</td> <td colspan="1" rowspan="1" align="left">--file</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Parses and executes the given filename to the <span class="option">-f</span> option. This switch is optional and can be left out. Only providing the filename to execute is sufficient. </p> <blockquote><p><b class="note">Note</b>: To pass arguments to scripts the first argument needs to be <i>--</i>, otherwise PHP will interperate them as PHP options. <br /> </p></blockquote> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-h and -?</td> <td colspan="1" rowspan="1" align="left">--help and --usage</td> <td colspan="1" rowspan="1" align="left"> With this option, you can get information about the actual list of command line options and some one line descriptions about what they do. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-i</td> <td colspan="1" rowspan="1" align="left">--info</td> <td colspan="1" rowspan="1" align="left"> This command line option calls <a href="function.phpinfo.html" class="function">phpinfo()</a>, and prints out the results. If PHP is not working correctly, it is advisable to use <strong class="command">php -i</strong> and see whether any error messages are printed out before or in place of the information tables. Beware that when using the CGI mode the output is in <i>HTML</i> and therefore quite huge. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-l</td> <td colspan="1" rowspan="1" align="left">--syntax-check</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> This option provides a convenient way to only perform a syntax check on the given PHP code. On success, the text <i>No syntax errors detected in <filename></i> is written to standard output and the shell return code is <i>0</i>. On failure, the text <i>Errors parsing <filename></i> in addition to the internal parser error message is written to standard output and the shell return code is set to <i>255</i>. </p> <p class="para"> This option won't find fatal errors (like undefined functions). Use <span class="option">-f</span> if you would like to test for fatal errors too. </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">-m</td> <td colspan="1" rowspan="1" align="left">--modules</td> <td colspan="1" rowspan="1" align="left"> <p class="para"><div class="informalexample"> <p class="para"> Using this option, PHP prints out the built in (and loaded) PHP and Zend modules: </p> <div class="example-contents"><pre><div class="cdata"><pre>$ php -m[PHP Modules]xmltokenizerstandardsessionposixpcreoverloadmysqlmbstringctype[Zend Modules]</pre></div> </pre></div> </div></p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-r</td> <td colspan="1" rowspan="1" align="left">--run</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> This option allows execution of PHP right from within the command line. The PHP start and end tags (<i><?php</i> and <i>?></i>) are <em class="emphasis">not needed</em> and will cause a parser error if present. </p> <blockquote><p><b class="note">Note</b>: Care has to be taken when using this form of PHP to not collide with command line variable substitution done by the shell. <br /> <div class="informalexample"> <p class="para"> Example showing a parser error </p> <div class="example-contents"><pre><div class="cdata"><pre>$ php -r "$foo = get_defined_constants();"Command line code(1) : Parse error - parse error, unexpected '='</pre></div> </pre></div> </div> The problem here is that the sh/bash performs variable substitution even when using double quotes <i>"</i>. Since the variable <var class="varname">$foo</var> is unlikely to be defined, it expands to nothing which results in the code passed to PHP for execution actually reading: <br /> <div class="informalexample"> <div class="example-contents"><pre><div class="cdata"><pre>$ php -r " = get_defined_constants();"</pre></div> </pre></div> <p class="para"> The correct way would be to use single quotes <i>'</i>. Variables in single-quoted strings are not expanded by sh/bash. </p> <div class="example-contents"><pre><div class="cdata"><pre>$ php -r '$foo = get_defined_constants(); var_dump($foo);'array(370) { ["E_ERROR"]=> int(1) ["E_WARNING"]=> int(2) ["E_PARSE"]=> int(4) ["E_NOTICE"]=> int(8) ["E_CORE_ERROR"]=> [...]</pre></div> </pre></div> </div> If you are using a shell different from sh/bash, you might experience further issues. Feel free to open a bug report at <a href="http://bugs.php.net/" class="link external">» http://bugs.php.net/</a>. 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. <br /> </p></blockquote> <blockquote><p><b class="note">Note</b>: <span class="option">-r</span> is available in the <em class="emphasis">CLI</em> SAPI and not in the <em class="emphasis">CGI</em> SAPI. <br /> </p></blockquote> <blockquote><p><b class="note">Note</b>: This option is meant for a very basic stuff. Thus some configuration directives (e.g. <a href="ini.core.html#ini.auto-prepend-file" class="link">auto_prepend_file</a> and <a href="ini.core.html#ini.auto-append-file" class="link">auto_append_file</a>) are ignored in this mode. <br /> </p></blockquote> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-B</td> <td colspan="1" rowspan="1" align="left">--process-begin</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> PHP code to execute before processing stdin. Added in PHP 5. </p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-R</td> <td colspan="1" rowspan="1" align="left">--process-code</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> PHP code to execute for every input line. Added in PHP 5. </p> <p class="para"> There are two special variables available in this mode: <var class="varname">$argn</var> and <var class="varname">$argi</var>. <var class="varname">$argn</var> will contain the line PHP is processing at that moment, while <var class="varname">$argi</var> will contain the line number. </p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-F</td> <td colspan="1" rowspan="1" align="left">--process-file</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> PHP file to execute for every input line. Added in PHP 5. </p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-E</td> <td colspan="1" rowspan="1" align="left">--process-end</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> PHP code to execute after processing the input. Added in PHP 5. </p> <p class="para"><div class="example"> <p><b>Example #2 Using the <span class="option">-B</span>, <span class="option">-R</span> and <span class="option">-E</span> options to count the number of lines of a project. </b></p> <div class="example-contents"><pre><div class="cdata"><pre>$ find my_proj | php -B '$l=0;' -R '$l += count(@file($argn));' -E 'echo "Total Lines: $l\n";'Total Lines: 37328</pre></div> </pre></div> </div></p> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">-s</td> <td colspan="1" rowspan="1" align="left">--syntax-highlight and --syntax-highlight</td> <td colspan="1" rowspan="1" align="left"> <p class="para"> Display colour syntax highlighted source. </p> <p class="para"> This option uses the internal mechanism to parse the file and produces a <i>HTML</i> highlighted version of it and writes it to standard output. Note that all it does it to generate a block of <i><code> [...] </code></i> <i>HTML</i> tags, no <i>HTML</i> headers. </p> <blockquote><p><b class="note">Note</b>: This option does not work together with the <span class="option">-r</span> option.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -