I have a js file which contains some data in the array form. http://localhost/js/data.js The information is something like
var subjectCodeArray=["CS/ Computer Science","AF/ Art Facalty",...];
and I want to get the information from the array "subjectCodeArray" into my php file "subjectCode.php" and then want to encode it into json array. I don't know how to do it pleas help me to do it.
thanks in advance.....
I got the answer first of all fatch the data from js file $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);
}
and finally encode in json form $output = json_encode(array('student_info'=>$json_response)); echo $output;