phpsanitization / phpsanitization
Simple PHP Sanitization Class
v1.0.13
2022-05-29 12:43 UTC
Requires
- php: ^7.3 || ^8.0
- ext-filter: *
Requires (Dev)
- ergebnis/composer-normalize: ^2.13.2
- ergebnis/license: ^1.1.0
- ergebnis/php-cs-fixer-config: ~2.13.0
- ergebnis/phpstan-rules: ~0.15.3
- ergebnis/test-util: ^1.4.0
- infection/infection: ~0.18.2
- maglnet/composer-require-checker: ^3.0
- ocramius/package-versions: *
- phpmd/phpmd: ^2.12
- phpstan/extension-installer: ^1.1.0
- phpstan/phpstan: ~0.12.71
- phpstan/phpstan-deprecation-rules: ~0.12.6
- phpstan/phpstan-phpunit: ~0.12.17
- phpstan/phpstan-strict-rules: ~0.12.9
- phpunit/phpunit: ^9
- psalm/plugin-phpunit: ~0.15.1
- squizlabs/php_codesniffer: *
- vimeo/psalm: ^4.4.1
README
PhpSanitization
About
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.
Features
- 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
Requirements
- PHP 8.0+
- Composer
How to install
$ composer require phpsanitization/phpsanitization
Usage
Class Inclusion
include_once 'vendor/autoload.php'; use PhpSanitization\PhpSanitization\Sanitization; use PhpSanitization\PhpSanitization\Utils; $sanitizer = new Sanitization(new Utils);
useSanitize
echo $sanitizer->useSanitize("<script>alert('xss');</script>");
useEscape
echo $sanitizer->useEscape("SELECT * FROM `users` WHERE `username` = 'admin';");
useTrim
echo $sanitizer->useTrim(" This is a text ");
useHtmlEntities
echo $sanitizer->useHtmlEntities("<script>alert('This is js code');</script>");
useFilterVar
echo $sanitizer->useFilterVar("This is a string");
useStripTags
echo $sanitizer->useStripTags("<script>alert('This is js code');</script>");
useStripSlashes
echo $sanitizer->useStripSlashes("C:\Users\Faris\Music");
useHtmlSpecialChars
echo $sanitizer->useHtmlSpecialChars("<script>alert('This is js code');</script>");
setData
$sanitizer->setData("This is data");
getData
echo $sanitizer->getData();
useStrReplace
echo $sanitizer->useStrReplace("text", "", "this is a text");
usePregReplace
echo $sanitizer->usePregReplace("/([A-Z])\w+/", "This is a Text");
validateEmail
echo $sanitizer->validateEmail("fake.email@gmail.com") ? "true" : "false";
isValid
echo $sanitizer->isValid("127.0.0.1", FILTER_VALIDATE_IP) ? "true" : "false";
isEmpty
echo $sanitizer->isEmpty($variable) ? "true" : "false";
isAssociative
echo $sanitizer->isAssociative($array) ? "true" : "fale";
callback
echo $sanitizer->callback(function () { return "text"; });
Screenshot
Documentation
The documentation for PhpSanitization is available here
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Copyright
Copyright (c) FarisCode - 2021