Call a PHP function from the command line

后端 未结 6 2099
野性不改
野性不改 2020-12-29 19:13

I have a file called address.php with a few functions in it. I want to call a specific function in that file from the command line. How?

The name of the function is

6条回答
  •  清歌不尽
    2020-12-29 19:53

    Add this to the top of the file "/var/www/test/address.php"...

    foreach ($argv as $i=>$arg )
    {
        if ( $arg == "exportAddress" )
        { 
            exportAddress($argv[$i+1]);
        }
    }
    

    Then from the command line, execute:

    php /var/www/test/address.php exportAddress 12345
    

提交回复
热议问题