欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP Command line

程序员文章站 2022-04-10 17:49:04
...
PHP 命令行获取传参

代码出处:http://www.haowei.me/archives/916.html
代码演示:http://www.haowei.me/archives/916.html?osc
  1. [hacker@broiler /]# php -r "echo \"PHP Command Line.\";"
  2. PHP Command Line.
  3. [hacker@broiler /]#
  4. [hacker@broiler /]#
  5. [hacker@broiler /]# php -r "echo __FILE__;"
  6. Command line code
  7. [hacker@broiler /]#
  8. [hacker@broiler /]#
  9. [hacker@broiler /]# php "test.php" 1 2 3 4
  10. int(5)
  11. Array
  12. (
  13. [0] => test.php
  14. [1] => 1
  15. [2] => 2
  16. [3] => 3
  17. [4] => 4
  18. )
  19. [hacker@broiler /]#
  20. [hacker@broiler /]#
  21. [hacker@broiler /]# cat test.php
  22. var_dump($_SERVER["argc"]);
  23. print_r($_SERVER["argv"]);
  24. [hacker@broiler /]#
  25. [hacker@broiler /]#
复制代码
相关标签: PHP Command line