Forum Moderators: coopster
function CleanString($string)
{
$out = "";
$length = strlen($string);
for($i = 0; $i < $length; $i++)
$out = $out . "&#" . ord(substr($string, $i, 1)) . ";";
return $out;
}
The function works great. The problem I am having is when I have something like:
<input type="checkbox" name="<?PHP echo $opt;?>">
Where $opt is a string encoded into the &#nnn; format. For some reason, I can only seem to access it as the unencoded string through the $_POST array. i.e., if the encoded string is, say, '88', then I can use $_POST['88']. I can't use the encoded version of '88' like $_POST['99']. And I would really like to be able to.
Is there some solution? I have tried different quotes, etc.
Btw, I am trying to acces it as $_POST[$opt], where $opt is the encoded version of the string.
Thanks
Rye
Anyway, I finally got frustrated with using entities on every char and have since started using htmlentities. The problem now, of course, is those special characters not taken care of by htmlentities.
I hate that my code must be peppered by a bunch of snippets of stripping code. :P It makes everything so messy.
Rye
$string = "They're a Lab\Shepard mix & only cost $25 each";
$string = addslashes(htmlentities($string));
echo $string;
output = They\'re a Lab\\Shepard mix & only cost $25 each
You don't mention what db you are using, but assuming MySQL, better to use mysql_real_escape_string() than addslashes()
WBF