从js文件中获取数组到php,然后编码为json


Fatch array from a js file into php and then encode into a json

我有一个js文件,其中包含数组形式的一些数据。http://localhost/js/data.js信息类似于

var subjectCodeArray=["CS/ Computer Science","AF/ Art Facalty",...]; 

,我想从数组"subjectCodeArray"的信息到我的php文件"subjectCode.php",然后要编码成json数组。我不知道怎么做,请帮我做一下。

thanks in advance.....

我得到了答案首先从js文件中获取数据$data = file_get_contents("./data.js");

Create a substring which contain the data from starting "[" to the ending "]"
$substrdata = substr($data, strpos($data,'[')+1, strpos($data,']') - strpos($data,'['));
then replase "'" with space
$substrdata = str_replace("'"", "", $substrdata);
then replace the singal cotes
$substrdata = str_replace("'", "", $substrdata);
and the explode it in the bases of comma and store it in array 
$arr=explode(",",$substrdata);
$json_response = array();
for($i=0;$i<count($arr);$i++)
{
    $row_array['student'] = preg_replace("/'//",'',$arr[$i]);
    array_push($json_response,$row_array);
}

,最后以json形式编码$output = json_encode(array('student_info'=>$json_response));echo $输出;