0

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 :

ù (&#195 &#185)

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;
}
}

1 Answers1

0

ù is "Mojibake" for ù.

See this for what to do about it.

Do not use any functions, such as utf8_decode; they will only make the problem worse.

Rick James
  • 135,179
  • 13
  • 127
  • 222