How to reverse FILTER_SANITIZE_SPECIAL_CHARS

Asked

Viewed 418 times

5

Guys I took a variable and converted her using the FILTER_SANITIZE_SPECIAL_CHARS.

Example:

filter_var ("hug' o", FILTER_SANITIZE_SPECIAL_CHARS);

The result:

hugD' o

How do I reverse this?

2 answers

6


Use the function html_entity_decode:

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

echo html_entity_decode($foo, ENT_QUOTES, "utf-8"); // hug' o
  • very good, thank you

2

According to the page of SANITIZE, the encoding was in ASCII. But as this case is encoding an apostrophe, It would be better if your Sanitize be like this:

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

Where:

FILTER_SANITIZE_STRING => Sanitizes the String

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

  • vlw, you help me a lot ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.