当前位置:Gxlcms > PHP教程 > PHPCommandline

PHPCommandline

时间:2021-07-01 10:21:17 帮助过:33人阅读

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 /]#

人气教程排行