
To call a Python file from a PHP file, you need to call it using the shell_exec function.
<?php
$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);
echo $output;
?>This will call the script. But in the script at the top, you also need to specify the interpreter. So, in your py file, add the following line at the top:
#!/usr/bin/env python
Alternatively, you can also provide an interpreter when executing the command.
<?php
$command = escapeshellcmd('python3 /usr/custom/test.py');
$output = shell_exec($command);
echo $output;
?>The above is the detailed content of How to call Python file from PHP?. For more information, please follow other related articles on the PHP Chinese website!
oncontextmenu incident
What are the css3 gradient properties?
What does STO mean in blockchain?
Binary representation of negative numbers
How to get http status code in PHP
What should I do if my iPad cannot be charged?
Ripple latest price
Solution to the problem that vscode cannot run after downloading python