开发者

PHP command line interface passing in multiple files

开发者 https://www.devze.com 2022-12-18 02:57 出处:网络
I\'m familiar with the basic of CLI and $argv array with php. Example: <?php // test.php var_dump($argv);

I'm familiar with the basic of CLI and $argv array with php. Example:

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

$php test.php dataf开发者_JAVA百科ile.txt 10 100

will produce:

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

What I'm trying to do is pass all files in a directory *.txt to php. Is there way I can do $php test.php *.txt and have all the filenames stored in an array?

Edit: for the solution I just use the glob function

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

?>


Take a look at the glob function. I assume you would just call it for every argument, using the argument as the parameter and merge the resultant arrays using array merge.

0

精彩评论

暂无评论...
验证码 换一张
取 消