PHP code example of nikaia / php-python-bridge
1. Go to this page and download the library: Download nikaia/php-python-bridge library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nikaia / php-python-bridge example snippets
use Nikaia\PythonBridge\Bridge;
try {
$response = Bridge::create()
->setPython('/usr/local/bin/python') // the path to the node (You can omit if in system path)
->setScript('/path/to/your/script.py') // the path to your script
->pipe(['foo' => 'bar']) // the data to pipe to the script
->run();
}
catch (BridgeException $e) {
echo $e->getMessage();
}
var_dump($response->json()); // ['foo' => 'bar']
var_dump($response->output()); // the raw output of the script {"foo":"bar"}
bash
composer