Getting HTMLEntities to work...
Posted: Sat Nov 11, 2006 2:48 pm
I can't seem to get htmlspecialchars or HTML_entities working...
I have a feeling its something really dumb I overlooked. Can anyone see my mistake?
This will simply return the original string unaltered. Even if it has quotes in it.
I have a feeling its something really dumb I overlooked. Can anyone see my mistake?
Code: Select all
// Unfinished filter function.
function filter($input, $type) {
// First clear the input of any HTML entities
$input = htmlspecialchars($input, ENT_QUOTES);
echo $input;
// Separate possible other "types"
$type = explode("-", $type);
// Now that the input is cleared as safe check it for content.
// Is the input an integer?
if ($type[0] == 'integer') {
// The number MUST be a number.
// Check it
if($input == '0' || is_int($input) == true) {
// The number is either 0 or another integer. Its cleared.
return $input;
}
} elseif ($type[0] == 'text') {
// Check if the input is text.
// Keep any \n's that could have been previously made.
$input = str_replace("\n", "\n<br />\n", $input);
return $input;
}
}