PDA

View Full Version : Common input functions


Mathias
August 18th, 2007, 08:54 PM
Note, all of my functions belong to classes, but I am posting only snippets of my functions to avoid boredom and giving away all my secrets. Please post corrections, suggestions, and your own related functions.

Mathias
August 18th, 2007, 08:55 PM
//-----------------------------------------------------------------------
// Function: GetInput
// Author: Andrew Hinkle
// Modified: 08/18/2007
// Description: Return the merged $_GET and $_POST input.
//-----------------------------------------------------------------------
public function GetInput()
{
return array_merge((array)$_GET, (array)$_POST);
}

Mathias
August 18th, 2007, 08:56 PM
//-----------------------------------------------------------------------
// Function: CleanInput
// Author: Andrew Hinkle
// Modified: 08/18/2007
// Description: Return the cleaned array.
//-----------------------------------------------------------------------
public function CleanInput($aInput)
{
// Stripslashes
if (is_array($aInput))
{
foreach ($aInput as $sKey => $sValue)
{
// If magic quotes is on, it will automatically add backslashes.
// Remove the extra slashes.
$sValue = get_magic_quotes_gpc() ? stripslashes($sValue) : $sValue;
$aInput[$sKey] = !empty($sValue) && !is_null($sValue) ? trim($sValue) : "";
}
}
else
{
// If magic quotes is on, it will automatically add backslashes.
// Remove the extra slashes.
$sValue = get_magic_quotes_gpc() ? stripslashes($aInput) : $aInput;
$aInput = !empty($sValue) && !is_null($sValue) ? trim($sValue) : "";
}

return $aInput;
}