Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在命令行+;非常基本_Php - Fatal编程技术网

Php 在命令行+;非常基本

Php 在命令行+;非常基本,php,Php,现在也许这是一个完全新手/愚蠢的问题,抱歉,但是 我有以下文件: $ cat helloWorldScript.php /*here I want to be able to run this in the command line witht the command pho scriptname.php. */ <?php Print "Hello, World!\n"; ?> 或者像这样使用-f参数-f Parse and execute. 但是为什么在执行文件时会显示注释呢

现在也许这是一个完全新手/愚蠢的问题,抱歉,但是

我有以下文件:

$ cat helloWorldScript.php
/*here I want to be able to run this in the command line
witht the command pho scriptname.php.
*/
<?php  Print "Hello, World!\n"; ?>
或者像这样使用-f参数
-f Parse and execute.

但是为什么在执行文件时会显示注释呢
使用
-f
有什么区别

我之所以这样问是因为我想使用php脚本将csv文件导入数据库,请参阅

我对a中的php有一些基本知识,但这里我有一个问题。

这些不是注释,因为它们在
标记之外

将开始标记移动到文件顶部,其行为应符合预期:

<?php
/*here I want to be able to run this in the command line
witht the command pho scriptname.php.
*/
Print "Hello, World!\n"; ?>

php标记中未包含的任何内容都不会被解析为代码

如果您的文件只包含代码(听起来像您的案例),这是常见的做法,甚至鼓励您打开
标记


请参阅。

这些不是注释,因为它们在
标记之外

将开始标记移动到文件顶部,其行为应符合预期:

<?php
/*here I want to be able to run this in the command line
witht the command pho scriptname.php.
*/
Print "Hello, World!\n"; ?>

php标记中未包含的任何内容都不会被解析为代码

如果您的文件只包含代码(听起来像您的案例),这是常见的做法,甚至鼓励您打开
标记

请参见。

是一个特殊的标记,用于描述代码的起始位置。除此之外的任何内容都被理解为“逐字打印”

为了获得您的
/**/注释若要不打印,您需要将它们包含在脚本的代码部分中:

<?php
/*here I want to be able to run this in the command line
witht the command pho scriptname.php.
*/
print "Hello, World!\n";
?>
然后
chmod+xmyscript.php
。然后您可以使用
/myscript从命令行调用它。php

是描述代码开始位置的特殊标记。除此之外的任何内容都被理解为“逐字打印”

为了获得您的
/**/注释若要不打印,您需要将它们包含在脚本的代码部分中:

<?php
/*here I want to be able to run this in the command line
witht the command pho scriptname.php.
*/
print "Hello, World!\n";
?>

然后
chmod+xmyscript.php
。然后,您可以使用
/myscript.php

从命令行调用它,以便在将其作为CLI脚本调用时对要使用的版本进行注释:通常,您只需选择更简单的“php[file]”,而不需要任何特殊参数,除了必需的参数。处理参数是一个完全不同的故事。@jonsurrell给出了答案,只是为了说明在将其作为CLI脚本调用时要使用哪个版本:通常您只需选择更简单的“php[file]”,而不需要任何特殊参数,除了必需的参数。处理参数是一个完全不同的故事。答案由@JonSurrell给出
#!/usr/bin/php
<?php
/*here I want to be able to run this in the command line
witht the command pho scriptname.php.
*/
print "Hello, World!\n";