note 51727 added to language.variables.external

From: Date: Fri, 08 Apr 2005 16:38:32 +0000
Subject: note 51727 added to language.variables.external
Groups: php.notes 
Request: Send a blank email to php-notes+get-87718@lists.php.net to get a copy of this message
To handle forms with or without [] you can do something like this: function repairPost($data) { // combine rawpost and $_POST ($data) to rebuild broken arrays in $_POST $rawpost = "&".file_get_contents("php://input"); while(list($key,$value)= each($data)) { $pos = preg_match_all("/&".$key."=([^&]*)/i",$rawpost, $regs, PREG_PATTERN_ORDER); if((!is_array($value)) && ($pos > 1)) { $qform[$key] = array(); for($i = 0; $i < $pos; $i++) { $qform[$key][$i] = urldecode($regs[1][$i]); } } else { $qform[$key] = $value; } } return $qform; } // --- MAIN $_POST = repairPost($_POST); The function will check every field in the $_POST with the raw post data and rebuild the arrays that got lost. ---- Manual Page -- http://www.php.net/manual/en/language.variables.external.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51727 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51727&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51727&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51727&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51727&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51727&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51727&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87718) next »