Skip to content

Instantly share code, notes, and snippets.

@aNd1coder
Created October 19, 2016 03:32
Show Gist options
  • Save aNd1coder/113961f920a634d4bdc03c5b746fe9fc to your computer and use it in GitHub Desktop.
Save aNd1coder/113961f920a634d4bdc03c5b746fe9fc to your computer and use it in GitHub Desktop.
Convert php object to json in nodejs
function PHP2JSON(phpFilePath) {
return new Promise(function(resolve, reject) {
childProcess.exec(
'php -r \'include("' + phpFilePath + '"); print json_encode($php_object);\'',
function(err, stdout, stderr) {
if (err) {
console.log(err)
return
}
resolve(JSON.parse(stdout))
}
)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment