php处理<;从命令行输入文件
我知道我可以在命令行/shell脚本上接收args,如下所示: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) {
!#/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,但内容类型:text/html;charset=UTF-8
-如何抑制这种情况?@oliverwillams脚本(或库)中的某些内容正在设置HTTP头。要抑制CLI上的头输出,请使用PHP-h
运行PHP。Matt I edited建议您的答案,哈希爆炸应该类似#/usr/bin/php-q
,以抑制这种情况。胡乱猜测-q代表安静;)非常简洁的回答。顺便说一句:shell脚本中引用的
)是什么?它没有特定的名称afaik,但内容类型:text/html;charset=UTF-8
-如何抑制这种情况?@oliverwillams脚本(或库)中的某些内容正在设置HTTP头。要抑制CLI上的头输出,请使用PHP-h
运行PHP。Matt I edited建议您的答案,哈希爆炸应该类似#/usr/bin/php-q
,以抑制这种情况。胡乱猜测-q代表安静;)