HTML
This is a form that accepts a user's input (url):
<form method="post" action="/" accept-charset="utf-8">
<input type="search" name="url" placeholder="Enter a url" />
<button>Go</button>
</form>
PHP (Laravel)
This controller stores the value of the user's input (url) into a variable for use in the python script.
$url = Input::get('url');
$name = shell_exec('path/to/python ' . base_path() . '/test.py ' . $url);
return $name;
Python
The script passes what the user input and takes the text after a forward slash and displays it.
url = sys.argv[1]
name = url.split('/')[-1]
print(name)
Going back to the PHP, it returns the value of what was executed in the Python script. If a user inputs the url: http://example.com/file.png it will successfully return the string file.png
Everything about this works, but I'm realizing that I'm limiting myself, since the shell_exec command is only going to paste out the string that is returned from the python script. What do I need to do if I want to have multiple variables returned?
Python in question
url = sys.argv[1]
name = url.split('/')[-1]
test = "pass this text too!"
# ? what goes here ?
So the HTML page should now return file.png and pass this text too!
Am I going to need to return an array or json in the python and then extract the array/json in PHP?
NOTE: I am aware of security flaws/injections in these examples, these are stripped down versions of my actual code.