0

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

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

$php test.php datafile.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]);

?>

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I'll look into glob. It's looks like a possible solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.