{"id":19,"date":"2014-11-07T04:25:33","date_gmt":"2014-11-06T22:25:33","guid":{"rendered":"http:\/\/shabab.me\/blog\/?p=19"},"modified":"2014-11-07T04:32:17","modified_gmt":"2014-11-06T22:32:17","slug":"get-all-php-post-data-array","status":"publish","type":"post","link":"https:\/\/shabab.me\/blog\/get-all-php-post-data-array\/","title":{"rendered":"How To: Get all PHP $_POST data in an array"},"content":{"rendered":"<p>Wondering how to get all PHP $_POST data in an array? Sometimes you may need to get \/ see the full $_POST (post method data) in order to debug\/change PHP code written by someone else. Perhaps a number of conditions work on what data was inserted there from a previous\/same page. So, you need to know what data was posted via $_POST method of PHP.<\/p>\n<p>If you know the array keys then you can check them out one by one. But how about if you don&#8217;t have any clue? Or want to find out what data was actually posted? Here comes php:\/\/input handy.<\/p>\n<p>PHP has a bunch of wrappers. <code>php:\/\/<\/code> is one of them which gives you access to various I\/O streams that PHP uses. <code>php:\/\/input<\/code> is one of them. ( there are a bunch of other streams available too: <a title=\"Accessing various I\/O streams\" href=\"http:\/\/php.net\/manual\/en\/wrappers.php.php\" target=\"_blank\">check out here<\/a> )<\/p>\n<p>So, here is a code snippet that will output the $_POST data as an associative array:<\/p>\n<pre class=\"lang:default decode:true \" title=\"Get $_POST data in a array\">    $post_data = explode( \"&amp;\", file_get_contents('php:\/\/input') );\r\n    $result = array();\r\n\r\n    foreach( $post_data as $post_datum ) {\r\n        $pair = explode(\"=\", $post_datum );\r\n\r\n        $result[urldecode($pair[0])] = urldecode($pair[1]);\r\n    }\r\n\r\n    print_r( $result );<\/pre>\n<p>Now you can debug the code efficiently. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wondering how to get all PHP $_POST data in an array? Sometimes you may need to get \/ see the full $_POST (post method data) in order to debug\/change PHP code written by someone else. Perhaps a number of conditions work on what data was inserted there from a previous\/same [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[3],"tags":[9,8],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-how-to","tag-how-to-2","tag-php"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/posts\/19"}],"collection":[{"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":5,"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":24,"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions\/24"}],"wp:attachment":[{"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shabab.me\/blog\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}