Run php code in command line

前端 未结 4 614
南笙
南笙 2021-01-01 10:38

I just began learning php. I\'ve installed php5 on linux and wrote very simple code just to get going.

How can I run scripts? I tried using the

4条回答
  •  执笔经年
    2021-01-01 10:57

    As already mentioned, you can execute your PHP with the following.

    $ php myScript.php
    

    If you wish to pass an argument(s), you can simply do so like this:

    $ php myScript.php Apples
    

    In your PHP file you can use this argument by accessing the $argv array like this:

    
    

    The above would print our "I like Apples". Note the array index is 1 and not 0. 0 is used for script name. In this case $argv would be "myScript.php"

    For more info check out my blog post Running PHP from the Command Line - Basics

提交回复
热议问题