【问题标题】:Call php function from bash - with arguments从 bash 调用 php 函数 - 带参数
【发布时间】:2015-01-21 08:01:24
【问题描述】:

我有一个带有 concat 函数的简单 func.php 文件:

<?php
function concat($arg1, $arg2)
    {
        return $arg1.$arg2;
    }
?>

我想用两个参数从 linux bash shell 调用这个函数:

1st: "Hello, "
2nd: "World!"

并将输出(“Hello, World!”)打印到 linux bash shell。

请告诉我,怎么做?

【问题讨论】:

    标签: php bash function shell call


    【解决方案1】:

    你想要的是$argv

    例如,您的脚本会这样调用:

    php /path/to/script.php 'Hello, ' 'World!'

    然后在你的 PHP 文件中:

    <?php
    $arg1 = $argv[1];
    $arg2 = $argv[2];
    
    echo concat($arg1, $arg2);
    
    function concat($arg1, $arg2) {
        return $arg1 . $arg2;
    }
    

    【讨论】:

    • 非常感谢Rjdown,这很有帮助! :)
    猜你喜欢
    • 2011-09-08
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    相关资源
    最近更新 更多