首頁  >  文章  >  後端開發  >  PHP Command line

PHP Command line

WBOY
WBOY原創
2016-07-25 08:48:351300瀏覽
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 /]#
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn