hirokawa                Sun Oct 28 18:15:30 2001 EDT

  Added files:                 
    /phpdoc/ja/appendices       commandline.xml 
  Log:
  added commandline.xml in japanese manual.
  

Index: phpdoc/ja/appendices/commandline.xml
+++ phpdoc/ja/appendices/commandline.xml
<?xml encoding="utf-8"?>
<!-- $Revision: 1.1 $ -->
<!-- 
   TODO:
   
     The command line options not in the
     list, but in the -h output below:
   
       -f, -e, -z, -l
    
     It would be best to document these, and
     collect more info about -c and -d!
-->
 <appendix id="commandline">
  <title>コマンドラインからPHPを使う</title>
  <para>
   
PHPコマンドライン版は、デバッグ時やPHPの設定をテストしたいような場
   
合には便利であるばかりでなく、Webスクリプト作成以外の用途にPHPを使
   用したい場合には、便利な選択肢です。
  </para>
  <para>
   
PHP実行ファイルの出力を外部ファイルに&gt;文字で常にリダイレクトでき、
   このため、<literal>php -q test.php > test.html</literal>は、
   <filename>test.php</filename>の出力をHTTPヘッダを付加せずに同じディ
   レクトリの<filename>test.html</filename>ファイルに出力します。
  </para>
  <para>
   
コマンドライン版は、PHP実行ファイルがある場合にのみ使用可能です。サー
   
バモジュール版を構築し、CGI版が使用するマシンで利用可能でない場合、
   
使用することはできません。Windowsユーザの場合、PHP実行ファイルとサー
   
バモジュールが共にバイナリパッケージに入っています。実行ファイルの
   名前は、<filename>php.exe</filename>です。
  </para>
  <para>
   以下にPHP 4.0.6に関するコマンドラインオプションを示します。
   <literal>-h</literal> 
オプションを使用することにより、実際のリスト
   とその簡単な説明を得ることが可能です。<literal>php -h</literal> 
の
   出力は、以下のようになります。
   <programlisting>
<![CDATA[
Usage: php [-q] [-h] [-s [-v] [-i] [-f <file>] |  {<file> [args...]}
  -q             Quiet-mode.  Suppress HTTP Header output.
  -s             Display colour syntax highlighted source.
  -f <file>      Parse <file>.  Implies `-q'
  -v             Version number
  -C             Do not chdir to the script's directory
  -c <path>      Look for php.ini file in this directory
  -d foo[=bar]   Define INI entry foo with value 'bar'
  -e             Generate extended information for debugger/profiler
  -z <file>      Load Zend extension <file>.
  -l             Syntax check only (lint)
  -m             Show compiled in modules
  -i             PHP information
  -h             This help
]]>
   </programlisting>  
  </para>
  <para>
   
以下に最も重要なコマンドラインオプションのいくつかについて詳細な解
   説を行います。
  </para>
  <para>
   <table>
    <title>コマンドラインオプション</title>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>オプション</entry>
       <entry>説明</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>-q</entry>
       <entry>
        
HTTPヘッダ出力を抑制します。通常、PHPはコールするプログラム(す
        
なわちWebサーバ)がブラウザに出力するようにHTTPヘッダを出力しま
        
す。コマンドラインアプリケーションを作成する場合には、これらの
        ヘッダは意味がありません。
       </entry>
      </row>
      <row>
       <entry>-s</entry>
       <entry>
        
ファイル名で指定されたファイルをカラーハイライト表示にして出力
        します。これは、PHPスクリプトでソースコードを
        <function>highlight_file</function>により出力するのと同じです。
       </entry>
      </row>
      <row>
       <entry>-v</entry>
       <entry>
        
このオプションを付けてPHPをコールすると、バージョン番号、すな
        わち、4.0.6を知ることができます。
       </entry>
      </row>
      <row>
       <entry>-C</entry>
       <entry>
        
通常、PHPは作業ディレクトリをスクリプトがあるディレクトリに変
        
更します。これにより、例えばファイル名を指定するだけで同じディ
        
レクトリにあるファイルをオープンすることが可能となります。
        
このディレクトリ変更を無効にしたい場合はこのオプションを使用し
        て下さい。
       </entry>
      </row>
      <row>
       <entry>-c</entry>
       <entry>
        このオプションを使用すると、別の<filename>php.ini</filename>
        
のパスを指定することが可能です。この場合、PHPは、デフォルトの
        パスの代わりに指定したパスで設定ファイルを探します。
       </entry>
      </row>
      <row>
       <entry>-d</entry>
       <entry>
        
このオプションを付けることにより、スクリプト実行時に、個々の
        <filename>php.ini</filename>設定を設定することが可能です。
       </entry>
      </row>
      <row>
       <entry>-m</entry>
       <entry>
        
このオプションにより、組み込まれた(そしてロードされた)PHPモジュー
        
ルおよびZendモジュール、PHPおよびZendのバージョン番号、Zendの
        著作権の簡略版を出力します。
      </entry>
      </row>
      <row>
       <entry>-i</entry>
       <entry>
        このコマンドラインオプションは、<function>phpinfo</function>を
        
コールし、結果を出力します。PHPが正しく動作しない場合、
        <literal>php -i</literal>を実行し、情報テーブルの前または中に
        出力されているエラーメッセージを確認して下さい。
       </entry>
      </row>
      <row>
       <entry>-h</entry>
       <entry>
        
このオプションを付けると、実際のコマンドラインオプション及びそ
        の簡単な説明を得ることができます。
       </entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </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
   <literal>php.exe -q</literal> 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.
  </para>
  <example>
   
<title>コマンドライン実行用に作成されたスクリプト(script.php)</title>
   <programlisting role="php">
<![CDATA[
#!/usr/bin/php -q
<?php

if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>

これは、オプションが1つあるコマンドライン版のPHPスクリプトです。

  使用法:
  <?php echo $argv[0]; ?> <option>

  <option> に出力したい何らかの単語を指定できます。
  --help, -help, -h, -? 
オプションを指定するとこのヘルプが表示されます。

<?php
} else {
    echo $argv[1];
}
?>
]]>
   </programlisting>
  </example>
  <para>
   In the script above, we used the special first line to indicate,
   that this file should be run by PHP and should not print out HTTP
   headers. 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>).
  </para>
  <para>
   In the program above we checked if there are less or more than one
   arguments. Also if the argument was <literal>--help</literal>,
   <literal>-help</literal>, <literal>-h</literal> or <literal>-?</literal>,
   we printed out the help message, printng the script name dynamically.
   If we received some other argument we echoed that out.
  </para>
  <para>
   If you would like to run the above script on Unix, you need to
   make it executable, and simply call it as
   <literal>script.php echothis</literal> or
   <literal>script.php -h</literal>. On Windows, you can make a
   batch file for this task:
  </para>
  <example>
   <title>
    
コマンドライン版PHPスクリプトを実行するバッチファイル(script.bat)
   </title>
   <programlisting>
@c:\php\php.exe -q script.php %1 %2 %3 %4
  </programlisting>
 </example>
 <para>
  Assuming, you named the above program as
  <filename>script.php</filename>, and you have your
  <filename>php.exe</filename> in
  <filename>c:\php\php.exe</filename> this batch file
  will run it for you with your added options:
  <literal>script.bat echothis</literal> or
  <literal>script.bat -h</literal>.
 </para>
</appendix>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

Reply via email to