note 52423 modified in language.variables.external by danbrown
| From: | danbrown@php.net | Date: | Wed, 09 Mar 2011 14:38:39 +0000 |
| Subject: | note 52423 modified in language.variables.external by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177702@lists.php.net to get a copy of this message | ||
This code module can be added to every form using require_once().
It will process any and all form data, prepending each variable with
a unique identifier (so you know which method was used to get the data).
My coding could be neater, but this sure makes processing forms much easier!
<?php
// -----------------------------------------------------------------
// Basic Data PHP module. This module captures all GET, POST
// and COOKIE data and processes it into variables.
// Coded April, 2005 by Timothy J. Pauly
// -----------------------------------------------------------------
//
// coo_ is prepended to each cookie variable
// get_ is prepended to each GET variable
// pos_ is prepended to each POST variable
// ses_ is prepended to each SESSION variable
// ser_ is prepended to each SERVER variable
session_start(); // initialize session data
$ArrayList = array("_POST", "_GET", "_SESSION", "_COOKIE",
"_SERVER"); // create an array of the autoglobal arrays
// we want to process
foreach($ArrayList as $gblArray) // process each array in the array list
{
$prefx = strtolower(substr($gblArray,1,3))."_"; // derive the prepend string
// from the autoglobal type name
$tmpArray = $$gblArray;
$keys = array_keys($tmpArray); // extract the keys from the array being processed
foreach($keys as $key) // process each key
{
$arcnt = count($tmpArray[$key]);
if ($arcnt > 1) // Break down passed arrays and
// process each element seperately
{
$lcount = 0;
foreach ($tmpArray[$key] as $dval)
{
$prkey = $prefx.$key; // create a new key string
// with the prepend string added
$prdata['$prkey'] = $dval; // this step could be eliminated
${$prkey}[$lcount] = $prdata['$prkey']; //create new key and insert the data
$lcount++;
}
} else { // process passed single variables
$prkey = $prefx.$key; // create a new key string
// with the prepend string added
$prdata['$prkey'] = $tmpArray[$key]; // insert the data from
// the old array into the new one
$$prkey = $prdata['$prkey']; // create the newly named
// (prepended) key pair using variable variables :-)
}
}
}
// -------------------------------------------------------------
?>
--was--
This code module can be added to every form using require_once().
It will process any and all form data, prepending each variable with
a unique identifier (so you know which method was used to get the data).
My coding could be neater, but this sure makes processing forms much easier!
<?php
// -----------------------------------------------------------------
// Basic Data PHP module. This module captures all GET, POST
// and COOKIE data and processes it into variables.
// Coded April, 2005 by Timothy J. Pauly
// www.timpauly.com
// -----------------------------------------------------------------
//
// coo_ is prepended to each cookie variable
// get_ is prepended to each GET variable
// pos_ is prepended to each POST variable
// ses_ is prepended to each SESSION variable
// ser_ is prepended to each SERVER variable
session_start(); // initialize session data
$ArrayList = array("_POST", "_GET", "_SESSION", "_COOKIE",
"_SERVER"); // create an array of the autoglobal arrays
// we want to process
foreach($ArrayList as $gblArray) // process each array in the array list
{
$prefx = strtolower(substr($gblArray,1,3))."_"; // derive the prepend string
// from the autoglobal type name
$tmpArray = $$gblArray;
$keys = array_keys($tmpArray); // extract the keys from the array being processed
foreach($keys as $key) // process each key
{
$arcnt = count($tmpArray[$key]);
if ($arcnt > 1) // Break down passed arrays and
// process each element seperately
{
$lcount = 0;
foreach ($tmpArray[$key] as $dval)
{
$prkey = $prefx.$key; // create a new key string
// with the prepend string added
$prdata['$prkey'] = $dval; // this step could be eliminated
${$prkey}[$lcount] = $prdata['$prkey']; //create new key and insert the data
$lcount++;
}
} else { // process passed single variables
$prkey = $prefx.$key; // create a new key string
// with the prepend string added
$prdata['$prkey'] = $tmpArray[$key]; // insert the data from
// the old array into the new one
$$prkey = $prdata['$prkey']; // create the newly named
// (prepended) key pair using variable variables :-)
}
}
}
// -------------------------------------------------------------
?>
http://php.net/manual/en/language.variables.external.php