-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
53 lines (48 loc) · 1.11 KB
/
index.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
$request = $_SERVER['REQUEST_METHOD'];
//determine
if(strtolower($request) != 'put'){
echo json_encode([
'status' => 'error',
'message' => 'method is not allow, using PUT'
]);
return false;
}
function put(){
parse_str(file_get_contents("php://input"), $_PUT);
$data = '';
foreach ($_PUT as $key => $value)
{
$clean_key = str_replace('_', ' ', $key);
$data = str_replace($clean_key.'=', '', $value);
$data = str_replace('"', '', $data);
}
$newArr = explode(PHP_EOL, $data);
$total = count($newArr);
$counter = 1;
foreach($newArr as $k => $val){
if($k == $counter){
unset($newArr[$k]);
$counter+=3;
}
}
unset($newArr[$total-=2]);
$c = 1;
$keyVal = [];
$last = '';
foreach($newArr as $key => $val)
{
if($c % 2 != 0){//if odd
//is key
$keyVal[$val] = '';
$last = $val;
}else{
//is val
$keyVal[$last] = $val;
}
$c++;
}
// var_dump($keyVal['id']);
var_dump($keyVal);
}
put();