Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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_Command Line Interface_Stdin - Fatal编程技术网

php处理<;从命令行输入文件

php处理<;从命令行输入文件,php,command-line-interface,stdin,Php,Command Line Interface,Stdin,我知道我可以在命令行/shell脚本上接收args,如下所示: !#/usr/bin/php <?php # file name - process.php print_r($argv); #/usr/bin/php 与C非常相似: <?php $stdin = fopen('php://stdin', 'r'); // Get the whole file, line by line: while (($line = fgets($stdin)) !== FALSE) {

我知道我可以在命令行/shell脚本上接收args,如下所示:

!#/usr/bin/php
<?php
# file name - process.php
print_r($argv);
#/usr/bin/php
与C非常相似:

<?php
$stdin = fopen('php://stdin', 'r');
// Get the whole file, line by line:
while (($line = fgets($stdin)) !== FALSE) {
    ...
}
?>
与C非常相似:

<?php
$stdin = fopen('php://stdin', 'r');
// Get the whole file, line by line:
while (($line = fgets($stdin)) !== FALSE) {
    ...
}
?>

Oliver,与其修改用户的帖子,不如发布不同的答案。以下是您打算发布的内容:

#!/usr/bin/php -q
<?php
    //NOTE the -q switch in hashbang above, silences MIME type output when reading the file!
    $stdin = fopen('php://stdin', 'r');
    // Get the whole file, line by line:
    while (($line = fgets($stdin)) !== FALSE) {
        ...
    }
?>
#/usr/bin/php-q

Oliver,与其修改用户的帖子,不如发布不同的答案。以下是您打算发布的内容:

#!/usr/bin/php -q
<?php
    //NOTE the -q switch in hashbang above, silences MIME type output when reading the file!
    $stdin = fopen('php://stdin', 'r');
    // Get the whole file, line by line:
    while (($line = fgets($stdin)) !== FALSE) {
        ...
    }
?>
#/usr/bin/php-q

非常简洁的答案。顺便说一句:shell脚本中引用的
)是什么?它没有特定的名称afaik,但被称为重定向运算符。此外,我正在将MIME类型回显到STDOUT(无论脚本中是否有任何编码)。即
内容类型:text/html;charset=UTF-8
-如何抑制这种情况?@oliverwillams脚本(或库)中的某些内容正在设置HTTP头。要抑制CLI上的头输出,请使用
PHP-h
运行PHP。Matt I edited建议您的答案,哈希爆炸应该类似
#/usr/bin/php-q
,以抑制这种情况。胡乱猜测-q代表安静;)非常简洁的回答。顺便说一句:shell脚本中引用的
)是什么?它没有特定的名称afaik,但被称为重定向运算符。此外,我正在将MIME类型回显到STDOUT(无论脚本中是否有任何编码)。即
内容类型:text/html;charset=UTF-8
-如何抑制这种情况?@oliverwillams脚本(或库)中的某些内容正在设置HTTP头。要抑制CLI上的头输出,请使用
PHP-h
运行PHP。Matt I edited建议您的答案,哈希爆炸应该类似
#/usr/bin/php-q
,以抑制这种情况。胡乱猜测-q代表安静;)