Maison  >  Article  >  développement back-end  >  PHP Command line

PHP Command line

WBOY
WBOYoriginal
2016-07-25 08:48:351300parcourir
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 /]#
复制代码


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn