Calling Python script from PHP - How to include variables?

Hi all!

Ok. I think my problem could be simple but I am not sure.
I can call a python script inside PHP like this:

$python = `python 1234`;
echo $python

The problem is that I would like to add a user-input value to be processed in python-script.
So I assume it would go like this when simplified:

$user_input = 1234;
$command = 'python';
$string = $command . ' ' . $user_input;
$python = $string;
echo $python;

Now the python-script is not executed. Any ideas what is my problem?

-Best wishes, Murzum

Ok. Found out the solution. Here it is:
In PHP-script:

$random_code_post = filter_input(INPUT_GET, 'user_input', FILTER_VALIDATE_INT);
$command = 'python ' . $random_code_post;
$python = `$command`;
echo $python;

Note the different apostophes/quotation marks when creating $command and $python!

And in I can for example print the value:


import sys

print sys.argv[1]