-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudents.php
29 lines (25 loc) · 872 Bytes
/
students.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
header('Content-type: application/json');
$K_CSV_SOURCE = '';
$K_NAME_INDEX = 0;
$K_PROGRAM_INDEX = 1;
$K_COUNTRY_INDEX = 4;
$K_UNIVERSITY_INDEX = 5;
$K_FIELDS_TO_KEEP = array($K_NAME_INDEX, $K_PROGRAM_INDEX, $K_COUNTRY_INDEX, $K_UNIVERSITY_INDEX);
$raw_csv = file_get_contents($K_CSV_SOURCE);
$student_data_array = explode("\n", $raw_csv);
foreach ($student_data_array as &$student_data) {
$student_data = str_getcsv($student_data);
}
array_shift($student_data_array); // get rid of table headers
foreach ($student_data_array as &$student_data) {
$useful_student_data = array();
foreach ($K_FIELDS_TO_KEEP as $field_to_keep) {
if(isset($student_data[$field_to_keep])) {
array_push($useful_student_data, $student_data[$field_to_keep]);
}
}
$student_data = $useful_student_data;
}
echo json_encode($student_data_array);
?>