Skip to content

Instantly share code, notes, and snippets.

@namnv609
Forked from sirkitree/node.js
Created December 30, 2015 16:41
Show Gist options
  • Save namnv609/d1e8159c448d189502f5 to your computer and use it in GitHub Desktop.
Save namnv609/d1e8159c448d189502f5 to your computer and use it in GitHub Desktop.
Parse a PHP file with Node.js and convert an array defined in the PHP script into a JSON object which the Node app can use.
var runner = require('child_process');
runner.exec(
'php -r \'include("settings.php"); print json_encode($databases);\'',
function (err, stdout, stderr) {
var connection = JSON.parse(stdout).default.default;
console.log(connection.database);
// result botdb
}
);
<?php
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'botdb',
'username' => 'botuser',
'password' => 'botpass',
'host' => 'localhost',
'prefix' => '',
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment