2

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

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

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

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

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

Please tell me, how to do it?

0

1 Answer 1

13

What you want is $argv

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

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

Then in your PHP file:

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

echo concat($arg1, $arg2);

function concat($arg1, $arg2) {
    return $arg1 . $arg2;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.