Let say I have this code in a JS file called plus2.js:
function plus2(n){
print (n+2);
};
plus2(n)开发者_JAVA技巧;
That's how it can be exacuted via PHP shell_exec:
echo shell_exec('js -f plus2.js');
Which doesn't return anythig because I have not informed a value to "n".
And that's the question: how can I pass a value to "n" via PHP shell_exec?
You can use the arguments
list:
function plus2(n){
print (n+2);
};
plus2(parseInt(arguments[0], 10));
Test:
[adrian@cheops3:~]> js test.js 1337
1339
To call it from your PHP code:
$result = system('js test.js 1337');
精彩评论