一:像命令行传参数方法:

1: 使用$argc $argv

用法: /usr/local/php/bin/php ./getopt.php 123  456

 

2:使用getopt函数()

http://php.net/manual/zh/function.getopt.php

用法:运行 /usr/local/php/bin/php ./getopt.php -f 123 -g 456

$options = "f:g:";

$opts = getopt( $options );

print_r($opts);

 

3: 提示用户输入,然后获取输入的参数。有点像C语言
用法: 在命令行下运行 /usr/local/php/bin/php ./getopt.php

fwrite(STDOUT, "Enter your name: ");
$name = trim(fgets(STDIN));
fwrite(STDOUT, "Hello, $name!");

方法一 使用$argc $argv

相关文章:

  • 2021-11-21
  • 2022-12-23
  • 2022-01-04
  • 2021-09-25
  • 2021-07-13
  • 2022-12-23
  • 2021-08-27
  • 2022-02-21
猜你喜欢
  • 2021-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
相关资源
相似解决方案