【问题标题】:PHP command line interface passing in multiple filesPHP命令行接口传入多个文件
【发布时间】:2010-01-27 22:44:22
【问题描述】:

我熟悉 CLI 和 $argv 数组与 php 的基础知识。 示例:

<?php // test.php
var_dump($argv);
?>

$php test.php 数据文件.txt 10 100

将产生:

array(4) {
  [0]=>
  string(8) "test.php"
  [1]=>
  string(12) "datafile.txt"
  [2]=>
  string(2) "10"
  [3]=>
  string(3) "100"
}

我想要做的是将目录 *.txt 中的所有文件传递给 php。有没有办法我可以做到$php test.php *.txt 并将所有文件名存储在一个数组中?

编辑:对于解决方案,我只使用 glob 函数

<?php
$files = glob($argv[1]);

?>

【问题讨论】:

    标签: php command-line


    【解决方案1】:

    看看glob function。我假设您只需为每个参数调用它,使用参数作为参数并使用数组合并合并结果数组。

    【讨论】:

    • 我会调查 glob。这看起来像是一个可能的解决方案
    猜你喜欢
    • 2016-01-17
    • 2021-05-15
    • 2012-07-08
    • 1970-01-01
    • 2012-07-20
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    相关资源
    最近更新 更多