/php-filter

A PHP based variable manipulation class

Primary LanguagePHPGNU Affero General Public License v3.0AGPL-3.0

Introduction

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.