如何将PHP数组传递给噩梦NodeJS脚本?这就是我的观点:
/*Original array $titles =
Array
(
[0] => title 1 with, a comma after with
[1] => title 2
[2] => title 3
[3] => title 4
)
*/
//PHP
$json_titles = json_encode($titles);
echo $json_titles;
// Output: ["title 1 with, a comma after with","title 2","title 3","title 4"]
// Pass to Nightmare NodeJS script with:
shell_exec('xvfb-run node app.js ' . $json_titles);
//NodeJS app.js:
const getTitles = process . argv[2];
console.log(getTitles)
// Output: [title 1 with, a comma after with,title 2,title 3,title 4]
如何将PHP中的相同数组转换为NodeJS?
正如你在下面看到的,西蒙带着逃脱来拯救他。谢谢西蒙!我还在Node JS脚本中多了一个步骤。我需要这样做: getTitles = JSON.parse(getTitles);
https://stackoverflow.com/questions/51896103
复制相似问题