htmlentities() will not work with my array
Posted: Thu Jan 22, 2009 9:42 pm
Hi guys,
I am trying to write a function that will take an array of strings and clean them up for secure input into the database.
So fa I have as follows:
The odd thing is that it will clean the string perfectly. Yet somehow when i print the array the strings are back to normal, and by that I mean that the '&' will be uncoded.
It somehow gets messed up when the strings are finally returned to the array.
Any ideas??
I am trying to write a function that will take an array of strings and clean them up for secure input into the database.
So fa I have as follows:
Code: Select all
<?php
function safe_input($params)
{
if(is_array($params))
{
foreach($params as $key => $string)
{
$string = clean_string($string);
}
}
else // just checks whether it is a simple string as opposed to an array
{
$params = clean_string($params);
}
return $params;
}
function clean_string($string)
{
$string = trim($string);
$string = strip_tags($string);
$string = htmlentities($string, ENT_QUOTES);
return $string;
}
$s = array('aaa' => 'Me & you', 'bbb' =>"Liz's stuff is boring", 'ccc' => 'One & two');
print_r(safe_input($s));
?>It somehow gets messed up when the strings are finally returned to the array.
Any ideas??