Re: Hidden Input and Quotes?

From: Date: Sat, 12 May 2001 00:24:07 +0000
Subject: Re: Hidden Input and Quotes?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52529@lists.php.net to get a copy of this message
> So my question is, should I (or, really, can I) encode it? My thinking is I > want to encode it with the htmlspecialchars() function... however, > eventually, all the data within the Hidden Input Boxes will be stored into > my mySQL database, so I'll want to decode it before I send it (restoring the > quotes)... is there a way to decode the htmlspecialchars() function? I ran into almost exactly the same problem. I was about ready to break down and hack out a regex when I came across the get_html_translation_table() function. This function lets you get the translation table used for the htmlspecialchars and htmlentities functions. So, for example: function my_htmlspecialchars ($string) { $trans_table = get_html_translation_table (HTML_SPECIALCHARS); return strtr($string, $trans_table); } This uses the strtr (STRing TRanslate) function to do the translation and does exactly the same thing as php's native htmlspecialchars(). To reverse things (replace the special chars with normal chars), we just need to flip the $trans_table around function strip_htmlspecialchars ($string) { $trans_table = get_html_translation_table (HTML_SPECIALCHARS); $trans_table = array_flip($trans_table); return strtr($string, $trans_table); } There ya go :) Regards, Sean

« previous php.general (#52529) next »