Reversing FILTER_SANITIZE_SPECIAL_CHARS

5

I took a variable and converted it using FILTER_SANITIZE_SPECIAL_CHARS .

Example:

filter_var ("hug' o", FILTER_SANITIZE_SPECIAL_CHARS);

The result:

hugD' o

How do I reverse this?

    
asked by anonymous 23.08.2016 / 21:26

2 answers

6

Use the html_entity_decode function:

$foo = filter_var ("hug' o", FILTER_SANITIZE_SPECIAL_CHARS);

echo html_entity_decode($foo, ENT_QUOTES, "utf-8"); // hug' o
    
23.08.2016 / 21:39
2

According to the SANITIZE of PHP page, the encoding was in ASCII. But as this case is encoding an apostrophe, it would be better for your sanitize to be like this:

$resposta = filter_var("hug' o",FILTER_SANITIZE_STRING,FILTER_FLAG_NO_ENCODE_QUOTES)

Where:

  

FILTER_SANITIZE_STRING = > Sanitiza a String

     

FILTER_FLAG_NO_ENCODE_QUOTES = > Treats the special character, as is the apostrophe, as well as quotation marks, will treat.

    
23.08.2016 / 21:43