Last active
March 31, 2024 11:45
-
-
Save pointofpresence/2d2d6f71e5ad1e177aa008023394a5d1 to your computer and use it in GitHub Desktop.
Как получить данные из тела запроса PUT, PATCH или DELETE?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Получение данных из тела запроса | |
function getFormData($method) { | |
// GET или POST: данные возвращаем как есть | |
if ($method === 'GET') return $_GET; | |
if ($method === 'POST') return $_POST; | |
// PUT, PATCH или DELETE | |
$data = array(); | |
$exploded = explode('&', file_get_contents('php://input')); | |
foreach($exploded as $pair) { | |
$item = explode('=', $pair); | |
if (count($item) == 2) { | |
$data[urldecode($item[0])] = urldecode($item[1]); | |
} | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment