Home >Backend Development >PHP Tutorial >The json string variable obtained by php parsing http is always blank null_PHP tutorial
This article mainly introduces the solution to the problem that the json string variable obtained by php parsing http is always blank and null. , a summary of personal experience, recommended here to everyone.
Today, a colleague encountered a problem in his project. The json string obtained through the http interface cannot be parsed correctly using json_decode and returns a blank.
Copy the result string directly and create a variable manually, but it works fine. It can also be parsed in the front-end js. I couldn’t figure it out for a long time. I solved the problem with the help of the powerful Google. The answer is that the result spit out by the interface contains a BOM header. The BOM header can be said to be the mortal enemy of PHP
No more talking, let’s go straight to the solution:
The code is as follows:
Record it here and share it with everyone. I hope it can be helpful to everyone.