Pass potentially infinite number of arguments to array except a single numeric variable in a PHP com
Posted
by tehalive
on Stack Overflow
See other posts from Stack Overflow
or by tehalive
Published on 2010-04-07T02:43:52Z
Indexed on
2010/04/07
3:03 UTC
Read the original article
Hit count: 342
I'm trying to make a PHP script that will take a potentially infinite number of URLs from the command line as arguments. I also need to pass an argument that only has a single numeric value possible (to specify timeout), e.g.:
./urltest.php 60 url1.com url2.com url3.com
I'm not exactly sure how to specify argv[1] to be a single numeric variable while at the same time the rest of the arguments (i.e. the list of urls) go into an array. Maybe something like:
$timeout = $argv[1];
$args = func_get_args();
function numfilter($num) {
return !is_numeric($num);
}
$urls = array_filters($args, 'numfilter');
?
Thanks in advance!
© Stack Overflow or respective owner