amattu2 / php-filter
A basic PHP input filter and validation class.
v1.0.0
2023-03-09 22:30 UTC
This package is not auto-updated.
Last update: 2025-01-11 05:29:04 UTC
README
This is a PHP class which implements static methods to filter/format unsanitized user input. See below for usage examples and cases. Alternatively, take a look at the index.php file for further examples.
Usage
Include the /src/Filter.php file
require(dirname(__FILE__) . "/src/Filter.php");
Methods
Filter::*input*(string $var)
Remove unprintable characters, HTML entities, and slashes.
Filter::*nonNumeric*(int|string|double|float $var)
Remove non-numeric characters
Filter::*nonAlpha*(mixed $var)
Remove non-alpha (a-zA-Z) characters
Filter::*nonAlphaNumeric*(mixed $var)
Remove non-alphanumeric (a-zA-Z0-9) characters
Filter::*fileName*(string $var)
Replace whitespace characters with a dash (-)
Filter::*number*(int|string $var)
Format a 10 digit phone number (XXX-XXX-XXXX)
Notes
You should always use prepared statements and proper validation on all unsafe input, regardless of using this class or not.