Jump to content

[SOLVED] Sanitizing array using strip_tags and htmlentities


allinurl

Recommended Posts

Hello. Im sanitizing an array of $_POST values with the function sanitize_values(), what Im trying to do now is to sanitize the array but instead of doing the way Im doing it

I would like to do it using strip_tags and htmlentities. What could be the best way of doing this using those functions mentioned before. Thanks in advance

 

function sanitize_values($value)
{
$search = array( '&', '\\', '<', '>', '[', ']' );
$replace = array( '&', '&#92;', '<', '>', '&#91;', '&#93;' );
$str = str_replace( $search, $replace, $str );
return( $str ); 
}

function sanitize_values($array)
{
foreach ($array as $k => $v)
{
$array[$k] = htmlentities(strip_tags($v),ENT_QUOTES);
}
return $array;
}

or:

function sanitize_values($val)
{
if (is_array($val))
{
  foreach ($val as $k => $v)
   {
   $val[$k] = htmlentities(strip_tags($v),ENT_QUOTES);
   }
  }
else
  {
  $val = htmlentities(strip_tags($val),ENT_QUOTES);
  }
return $val;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.