downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

$argv> <$http_response_header
[edit] Last updated: Fri, 25 May 2012

view this page in

$argc

(PHP 4, PHP 5)

$argcスクリプトに渡された引数の数

説明

コマンドラインから実行したときに、 現在のスクリプトに渡された引数の数が含まれます。

注意: スクリプトのファイル名は、常にスクリプトへの引数として渡されます。 したがって、$argc の最小値は 1 です。

注意: この変数は、register_argc_argv が無効になっている場合には使えません。

例1 $argc の例

<?php
var_dump
($argc);
?>

このサンプルを php script.php arg1 arg2 arg3 と実行します。

上の例の出力は、 たとえば以下のようになります。

int(4)



$argv> <$http_response_header
[edit] Last updated: Fri, 25 May 2012
 
add a note add a note User Contributed Notes $argc
Tejesember 04-May-2011 06:50
To find out are you in CLI or not, this is much better in my opinion:
<?php
if (PHP_SAPI != "cli") {
    exit;
}
?>
anonymous 21-Oct-2010 11:26
I use the following lines to check if i'm using CLI mode or not :

<?php
$cli_mode
= false;
if ( isset(
$_SERVER['argc']) && $_SERVER['argc']>=1 ) {
 
$cli_mode = true;
}
?>
karsten at typo3 dot org 18-Feb-2009 09:47
Note: when using CLI $argc (as well as $argv) are always available, regardless of register_argc_argv, as explained at http://docs.php.net/manual/en/features.commandline.php

 
show source | credits | stats | sitemap | contact | advertising | mirror sites