用php编码javascript数组?

用php编码javascript数组?,javascript,php,json,Javascript,Php,Json,我尝试在php中对javascript数组进行编码,但没有成功。。。我不明白问题出在哪里: 这是我的javascript代码 var reports = [ ["grup",24.5,101.6,"680 C.","680 C.",0,"N"], ["vul-Aca",4.501,-9.876,"192 C.","192 C.",0,"N"] ]; 我试着这样编码: $file= "jsfolder/arr

我尝试在
php
中对javascript数组进行编码,但没有成功。。。我不明白问题出在哪里:

这是我的javascript代码

var reports = [
               ["grup",24.5,101.6,"680 C.","680 C.",0,"N"],
               ["vul-Aca",4.501,-9.876,"192 C.","192 C.",0,"N"]
              ];
我试着这样编码:

$file= "jsfolder/array.js"; //here there is only that js array
$file_contents = file_get_contents($file);
$json_string_array = substr($file_contents,strpos($file_contents,'['),-1);
$array_php = json_decode($json_string_array);
但我认为这是一个错误:(


非常感谢并为我的英语感到抱歉

你也必须去掉字符串末尾的分号

php > var_dump(json_decode("[];"));
NULL
php > var_dump(json_decode("[]"));
array(0) {}

您还必须去掉字符串末尾的分号

php > var_dump(json_decode("[];"));
NULL
php > var_dump(json_decode("[]"));
array(0) {}

PHP具有在PHP中运行javascript代码的扩展

在php中安装V8JS扩展。此后,您可以执行您正在尝试的操作。 从文件中获取内容

$file= "jsfolder/array.js"; //here there is only that js array
$file_contents = file_get_contents($file);

V8JS::executestring方法然后执行作为javascript代码提供的字符串。这将返回php中定义的数组,然后您可以在php中继续操作php具有在php中运行javascript代码的扩展名

在php中安装V8JS扩展。此后,您可以执行您正在尝试的操作。 从文件中获取内容

$file= "jsfolder/array.js"; //here there is only that js array
$file_contents = file_get_contents($file);
V8JS::executestring方法然后执行作为javascript代码提供的字符串。这将返回php中定义的数组,然后您可以在php中继续操作

您的代码工作正常-您的代码工作正常-