I'm using PHP filter_input function to sanitize POST parameters on my site.
Code :
$text = trim(filter_input(INPUT_POST, 'text', FILTER_SANITIZE_STRING,
array('flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_ENCODE_HIGH)));
Now, if i insert characters like "ù" this is the encoded result :
ù (à ¹)
My database tables are encoded in utf8_general_ci. Now, i tried with the function
utf8_decode($data)
but it's not working. Please help on how to restore characters encoded with FILTER_FLAG_ENCODE_HIGH parameter ?
EDIT : here's my connection class
class Connection{
protected $db =null;
public function open()
{
try {
$dsn = "mysql:dbname="x"; host=127.0.0.1;charset=utf8";
$user = "user";
$password = "password";
$options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
);
$this->db = new PDO($dsn, $user, $password, $options);
return $this->db;
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
}
public function close()
{
$this->db = null;
return true;
}
}