从bash调用php函数-带参数 [英] Call php function from bash - with arguments

查看:56
本文介绍了从bash调用php函数-带参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 func.php 文件,该文件具有 concat 功能:

I have a simple func.php file with concat function:

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

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

I would like to call this function from linux bash shell with two arguments :

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

并将输出("Hello,World!")输出到linux bash shell.

and print the output ("Hello, World!") to linux bash shell.

请告诉我,怎么做?

推荐答案

您想要的是例如,您的脚本将被这样命名:

So for example, your script would be called like this:

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

然后在您的PHP文件中:

Then in your PHP file:

<?php
$arg1 = $argv[1];
$arg2 = $argv[2];

echo concat($arg1, $arg2);

function concat($arg1, $arg2) {
    return $arg1 . $arg2;
}

这篇关于从bash调用php函数-带参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆