Re: array_map help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mark Steudel wrote:
I've got the following code and I am not doing something right. Either my
function is wrong, or the way Im using array_map is wrong, as slashes are
still making it into the data, and the asdf iosn't getting appended to each
value.

I rewrote what you had like so:

<?php
function detectMGQ($value)
{
   //return get_magic_quotes_gpc() ? stripslashes($value): $value;
   return $value."-TEST";
}

$clean = array(
    "name"          => "name",
    "email"         => "email",
    "username"      => "username",
    "accesslevel"   => "accesslevel",
    "status"        => "status",
);

$field_values = array_map( "detectMGQ", $clean );
var_dump($field_values);
?>

and it adds '-TEST' to every value as expected. not sure whats going
wrong with your code exactly by I have got some general comments...
(maybe the code I rewrote helps you to figure otu what was/is going
wrong.)


Thanks, Mark



// function to remove stripped slashes
function detectMGQ($value)
{
   // Stripslashes
   if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
   }
// added in to detect if this function is working
   $value .= $value.'asdf';

if $value equals "ABC" then it would equal "ABCABCasdf" aftyer
that last line of code was run.


   return $value;
}

// construct field and value pairs into array
$field_values	=	array(	'name'		=> "$clean[name]",
						'email'		=>
"$clean[email]",

  yuou don't need to wrap $clean[email] in quotes - it's waste of
time+cpu BUT you should always delimit the array key with quotes because
it is a string not a constant (or does you code actually define a constant
named 'email'?) i.e.

"$clean[email]" is better off being $clean['email']

						'username'		=>
"$clean[username]",
						'accesslevel'	=>
"$clean[accesslevel]",
						'status'		=>
"$clean[status]",
						'password'		=>
base64_encode(rc4($clean[password1])) );
			

// walk through the values and strip out the slashses
$field_values = array_map( "detectMGQ", $field_values );


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux