Code Monkey home page Code Monkey logo

phpsanitization's Introduction

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

  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("[email protected]") ? "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

phpsanitization's People

Contributors

dependabot[bot] avatar farisc0de avatar fossabot avatar hadialqattan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.