PHP Classes

PHP Sanitize String: Remove insecure or unnecessary parts of a string

Recommend this page to a friend!
  Info   View files Documentation   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2022-08-19 (3 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 89 All time: 9,788 This week: 138Up
Version License PHP version Categories
sanitizer 1.0MIT/X Consortium ...5PHP 5, Text processing, Security
Description Author

This package can remove insecure or unnecessary parts of a string.

It can take a string of text and process it to tell if there are insecure parts or other parts that do not comply with a specific format.

Currently, it can:

- Detect and alert when there are HTML tags with JavaScript code that may abuse users' private data

- Remove HTML tags from the text string

- Perform filtering with a custom function

Picture of Maniruzzaman Akash
  Performance   Level  
Name: Maniruzzaman Akash <contact>
Classes: 13 packages by
Country: Bangladesh Bangladesh
Age: 26
All time rank: 390447 in Bangladesh Bangladesh
Week rank: 93 Up7 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 4x

Details

PHP Sanitizer

Sanitize and escape every values in your PHP Application.

This solution will make PHP developer life easy, very easy and developers would be able to create a secure application quickly and effortlessly.

Let's see inside of this.

Requirement

  • PHP: 7.1 or later
  • PHP Unit (in dev): 7

Latest Version

0.0.7

How to install

composer require maniruzzaman/sanitizer

Documentation

Instantiation and loading.

// at top of the class autoload
use Maniruzzaman\Sanitizer\Sanitize;

// instantiate anywhere if needed
$sanitize = new Sanitize();

Sanitize Text

Example 1: Sanitize text with script:

$string  = 'Text with script <script>alert("you are hacked...")</script>';
Sanitize::text($string);
#Output: Text with issuealert(&quot;you are hacked...&quot;)

Example 2: Sanitize text with html texts:

$string  = 'Text with script <strong>This is strong text</strong>';
Sanitize::text($string);
#Output: Text with script This is strong text

Sanitize Attribute

Example 3: Sanitize attribute to filter out unnecessary strings:

$string  = 'https://devsenv.com<script>welcome</script>';

$sanitize = new Sanitize();
$sanitize->attr($string);
#Output: https:://devsenv.com

More is coming...

Testing

We've used PHPUnit to test our codes.

Check if everything passes test cases or not. You can check our test cases to see the implementations of Sanitizer.

// For full directory
phpunit tests

// For specific file test
phpunit tests/SanitizeTest.php

Release Notes:

Release version 0.0.7

  • [Enhancement] Added unit test for text() helper sanitize function.
  • [Enhancement] Added some security and fund links

Release version 0.0.6

  • [Enhancement] Updated some doc-block
  • [Enhancement] Structured some code base
  • [Enhancement] Updated Minimum PHP Version requirement
  • [Enhancement] Added PHP Unit test support dev package

Release version 0.0.5

  • Fixed some autoloading issue with documenting

Release version 0.0.4

  • Fixed autoloading functions

Release version 0.0.3

  • Removed some unused autoload dependency

Release version 0.0.2

  • Added `Url` Sanitization

Release version 0.0.1

  • Release some simple escaping functions.
  • Added `text` sanitization
  • Added `attribute` sanitization

License

The Library is open-sourced software licensed under the <a href="https://opensource.org/licenses/MIT">MIT license</a>.

Support

Do you wanna support me to buy a coffee? Please be one of my patreon - https://www.patreon.com/maniruzzaman

  Files folder image Files  
File Role Description
Files folder image.github (2 files)
Files folder imagesrc (2 files, 2 directories)
Files folder imagetests (1 file)
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 phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
  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  /  src  
File Role Description
Files folder imageFormatter (1 file)
Files folder imageInterfaces (1 file)
  Accessible without login Plain text file functions.php Aux. Auxiliary script
  Plain text file Sanitize.php Class Class source

  Files folder image Files  /  src  /  Formatter  
File Role Description
  Plain text file Utf8Formatter.php Class Class source

  Files folder image Files  /  src  /  Interfaces  
File Role Description
  Plain text file FormatterInterface.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file SanitizeTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:89
This week:0
All time:9,788
This week:138Up