Simple PHP Sanitization Class
This is a simple class that can verify and clean values to assure they are valid.
It can take a given string and remove or encode certain types of text values, so it can be displayed in Web pages lowering the risk of being used to perform security attacks.
The class can also sanitize arrays of data by processing the array values one by one.
- Out-Of-The-Box
- Support String, Arrays, and Associative Arrays
- Escape PDO and SQL queries
- Sanitize and validate email
- Built-in methods for custom sanitization
- Easy to Use
- PHP 8.0+
- Composer
$ composer require phpsanitization/phpsanitization
include_once 'vendor/autoload.php';
use PhpSanitization\PhpSanitization\Sanitization;
use PhpSanitization\PhpSanitization\Utils;
$sanitizer = new Sanitization(new Utils);
echo $sanitizer->useSanitize("<script>alert('xss');</script>");
echo $sanitizer->useEscape("SELECT * FROM `users` WHERE `username` = 'admin';");
echo $sanitizer->useTrim(" This is a text ");
echo $sanitizer->useHtmlEntities("<script>alert('This is js code');</script>");
echo $sanitizer->useFilterVar("This is a string");
echo $sanitizer->useStripTags("<script>alert('This is js code');</script>");
echo $sanitizer->useStripSlashes("C:\Users\Faris\Music");
echo $sanitizer->useHtmlSpecialChars("<script>alert('This is js code');</script>");
$sanitizer->setData("This is data");
echo $sanitizer->getData();
echo $sanitizer->useStrReplace("text", "", "this is a text");
echo $sanitizer->usePregReplace("/([A-Z])\w+/", "This is a Text");
echo $sanitizer->validateEmail("fake.email@gmail.com") ? "true" : "false";
echo $sanitizer->isValid("127.0.0.1", FILTER_VALIDATE_IP) ? "true" : "false";
echo $sanitizer->isEmpty($variable) ? "true" : "false";
echo $sanitizer->isAssociative($array) ? "true" : "fale";
echo $sanitizer->callback(function () {
return "text";
});
The documentation for PhpSanitization is available here
Please have a look at CHANGELOG.md
.
Please have a look at CONTRIBUTING.md
.
Please have a look at CODE_OF_CONDUCT.md
.
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Copyright (c) FarisCode - 2021