Forum Moderators: coopster

Message Too Old, No Replies

Cleaning an array

Array submitted via a html form. How to best "clean" it?

         

IamStang

1:24 am on Feb 15, 2006 (gmt 0)

10+ Year Member



I have a form that submits an array. Such as:
<input type="text" name="aName[]">
<input type="text" name="aName[]">
<input type="text" name="aName[]">
<input type="text" name="aName[]">

I need to "clean" this info before inserting it into a database, etc.

I have tried using the following (which throws out errors each time):

$aName = htmlspecialchars(addslashes($_POST['aName']));

and

if(is_array($appr))
{
for ($i=0;$i<count($aName);$i++)
{
$aName[$i] = htmlspecialchars(addslashes($_POST['aName[$i]']));

How can I clean this info?

Any and all help is greatly appreciated.

Regards,
IamStang

omoutop

8:16 am on Feb 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Better clean each part of the array rather the array itself....

foreach ($array_name as $temp_var)
{
// clean (or whatever) $temp_var

// since $temp_var is modified
$new_array[] = $temp_var;
}

Hope this helps