PHP sanitize string input with the filter function
December 5th, 2007 by admin
The PHP filter function is a new function in PHP5. It is already showing a lot of promise and is going to be an attractive alternative to older functions such as strip_tags(). Basically, when sanitizing a strin with the filter function you are removing unwanted and unsafe parts of the input, and leave the rest unharmed.
In this tutorial I will show you how to filter unwanted tags from an input using this function
FILTER_SANITIZE_STRING this will strip tags from a string. It can also optionally strip or encode special characters.
1 2 3 4 5 | <?php $input = "copy<html>"; $output = filter_var($input, FILTER_SANITIZE_STRING); echo $output; ?> |
So the above will return: copy
Posted in PHP Code