Reverse FILTER_SANITIZE_SPECIAL_CHARS with PHP

This is a simple question, but I'm a newbie, so please forgive my simple question.

Is there an easy way to reverse the filter effect FILTER_SANITIZE_SPECIAL_CHARS? If not, how would you cancel it. Please do not just say regular expressions, actually suggest how to do this. To be clear, I am not trying to change the line.

Here is a sample code to help explain what I want to do:

/*** a string with tags ***/
$string = "<li><script>!@#$%^&*\n\'#foo</script><br><p /><li />";

/*** sanitize the string ***/
$x = filter_var($string, FILTER_SANITIZE_SPECIAL_CHARS);
echo $x . "<br>\n";

/*** I want this to output <li><script>!@#$%^&*\n\'#foo</script><br><p /><li /> ***/
echo htmlspecialchars_decode($x);
/*** instead it outputs: &#60;li&#62;&#60;script&#62;!@#$%^&#38;*&#10;\&#39;#foo&#60;/script&#62;&#60;br&#62;&#60;p /&#62;&#60;li /&#62; ***/

Any ideas will be appreciated. Thanks in advance.

+3
source share
1 answer

Consider a html_entity_decode()more complete version htmlspecialchars_decode().

+3
source

All Articles