Use PHP to receive POST data and parse json data

Source: Internet
Author: User
This article describes how to use PHP to receive POST data and json data. For more information, see The code is as follows:


$ Json_string = $ _ POST ["txt_json"];
If (ini_get ("magic_quotes_gpc") = "1 ")
{
$ Json_string = stripslashes ($ json_string );
}
$ User = json_decode ($ json_string );
Echo var_dump ($ user );
?>


In this file, first obtain the value of the POST form field txt_json in the html file, put it in the variable $ json_string, and then judge, if the current PHP is set to magic_quotes_gpc = On, that is, the passed double quotation marks will be escaped, so that the json_decode function cannot be parsed. Therefore, we need to reverse it. Then, use the json_decode function to convert the JSON text into an object, save it in the $ user variable, and finally use echo var_dump ($ user); to output the dump of the object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.