Sometimes, we want to read JSON POST using PHP.
In this article, we’ll look at how to read JSON POST using PHP.
How to read JSON POST using PHP?
To read JSON POST using PHP, we call file_get_contents
.
For instance, we write
$json = file_get_contents('php://input');
$obj = json_decode($json);
to call file_get_contents
with 'php://input'
to read in JSON request body data.
And then we call json_decode
to decode the $json
string into an object.
Conclusion
To read JSON POST using PHP, we call file_get_contents
.