Sometimes, we want to receive JSON POST with PHP.
In this article, we’ll look at how to receive JSON POST with PHP.
How to receive JSON POST with PHP?
To receive JSON POST with PHP, we can use the json_decode
function.
For instance, we write
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data["operation"];
to call json_code
with the JSON POST data, which is returned in
file_get_contents('php://input')
We then get the value of the entry with key operation
from the $data
associative array.
Conclusion
To receive JSON POST with PHP, we can use the json_decode
function.