PHP Classes

PHP Data Sanitization: Verify and clean values to ensure they are valid

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 82 All time: 10,078 This week: 37Up
Version License PHP version Categories
phpsanitization 1.0.0Custom (specified...7PHP 5, Text processing, Validation, P...
Description 

Author

This package can verify and clean values to ensure they are valid.

It provides functions that can take string values and verify if they have a specific format.

The package also provides functions to clean the string values to make them have a desired format.

Currently, it can:

- Remove harmful JavaScript code from HTML

- Escape SQL values from queries

- Trim whitespace from the beginning or end of a string

- Encode special HTML characters

- Filter values

- Strip HTML tags

- Strip slashes

- Replace certain strings

- Validate email addresses

- Validate IP addresses

- Validate empty strings

- Check if an array is associative

- Validate a string using a callback function

Picture of Faris AL-Otabi
  Performance   Level  
Name: Faris AL-Otabi <contact>
Classes: 16 packages by
Country: Saudi Arabia Saudi Arabia
Age: 27
All time rank: 276010 in Saudi Arabia Saudi Arabia
Week rank: 9 Up1 in Saudi Arabia Saudi Arabia Up
Innovation award
Innovation award
Nominee: 5x

Winner: 1x

Example

<?php

echo $sanitizer->validateEmail("fake.email@gmail.com") ? "true" : "false";


Details

<p align="center">

<img align="center" src="https://d.top4top.io/p_1862a8k1e1.png" height="350px" />

</p>

PhpSanitization

![](https://img.shields.io/github/license/farisc0de/PhpSanitization) ![](https://img.shields.io/github/v/tag/farisc0de/PhpSanitization) ![](https://img.shields.io/github/repo-size/farisc0de/PhpSanitization) ![](https://img.shields.io/github/languages/top/farisc0de/PhpSanitization) ![](https://img.shields.io/github/commits-since/farisc0de/PhpSanitization/v1.0.11)

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

  1. Out-Of-The-Box
  2. Support String, Arrays, and Associative Arrays
  3. Escape PDO and SQL queries
  4. Sanitize and validate email
  5. Built-in methods for custom sanitization
  6. Easy to Use

Requirements

  1. PHP 8.0+
  2. 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

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.

FOSSA Status

Copyright

Open Source Love

Copyright (c) FarisCode - 2021


  Files folder image Files (50)  
File Role Description
Files folder image.github (5 files, 2 directories)
Files folder image.phive (1 file)
Files folder imageexamples (20 files)
Files folder imagesrc (2 files)
Files folder imagetest (1 file)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .phpcs.xml Data Auxiliary data
Accessible without login Plain text file .yamllint.yaml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file codecov.yml Data Auxiliary data
Accessible without login Plain text file composer-require-checker.json Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file infection.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file Makefile Data Auxiliary data
Accessible without login Plain text file phpstan-baseline.neon Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file psalm-baseline.xml Data Auxiliary data
Accessible without login Plain text file psalm.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (50)  /  .github  
File Role Description
Files folder imageISSUE_TEMPLATE (3 files)
Files folder imageworkflows (1 file)
  Accessible without login Plain text file CODE_OF_CONDUCT.md Data Auxiliary data
  Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
  Accessible without login Plain text file dependabot.yml Data Auxiliary data
  Accessible without login Plain text file FUNDING.yml Data Auxiliary data
  Accessible without login Plain text file SECURITY.md Data Auxiliary data

  Files folder image Files (50)  /  .github  /  ISSUE_TEMPLATE  
File Role Description
  Accessible without login Plain text file bug_report.md Data Auxiliary data
  Accessible without login Plain text file custom.md Data Auxiliary data
  Accessible without login Plain text file feature_request.md Data Auxiliary data

  Files folder image Files (50)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data

  Files folder image Files (50)  /  .phive  
File Role Description
  Accessible without login Plain text file phars.xml Data Auxiliary data

  Files folder image Files (50)  /  examples  
File Role Description
  Accessible without login Plain text file callback_example.php Example Example script
  Accessible without login Plain text file data_getter_example.php Example Example script
  Accessible without login Plain text file data_setter_example.php Example Example script
  Accessible without login Plain text file email_validate_example.php Example Example script
  Accessible without login Plain text file escape_sql_query_example.php Example Example script
  Accessible without login Plain text file index.php Example Example script
  Accessible without login Plain text file is_associative_exmaple.php Example Example script
  Accessible without login Plain text file is_empty_example.php Example Example script
  Accessible without login Plain text file is_valid_example.php Example Example script
  Accessible without login Plain text file preg_replace_example.php Example Example script
  Accessible without login Plain text file sanitize_array_example.php Example Example script
  Accessible without login Plain text file sanitize_associative_array_example.php Example Example script
  Accessible without login Plain text file sanitize_string_example.php Example Example script
  Accessible without login Plain text file str_replace_example.php Example Example script
  Accessible without login Plain text file use_filter_var_example.php Example Example script
  Accessible without login Plain text file use_html_entities_example.php Example Example script
  Accessible without login Plain text file use_html_special_chars_example.php Example Example script
  Accessible without login Plain text file use_strip_slashes_example.php Example Example script
  Accessible without login Plain text file use_strip_tags_example.php Example Example script
  Accessible without login Plain text file use_trim_example.php Example Example script

  Files folder image Files (50)  /  src  
File Role Description
  Plain text file Sanitization.php Class Class source
  Plain text file Utils.php Class Class source

  Files folder image Files (50)  /  test  
File Role Description
  Plain text file SanitizationTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:82
This week:0
All time:10,078
This week:37Up