PHPackages                             initphp/escaper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. initphp/escaper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

initphp/escaper
===============

InitPHP Escaper Class

1.0(4y ago)1381MITPHPPHP &gt;=7.4

Since Mar 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/InitPHP/Escaper)[ Packagist](https://packagist.org/packages/initphp/escaper)[ RSS](/packages/initphp-escaper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

InitPHP Escaper
===============

[](#initphp-escaper)

Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs.

[![Latest Stable Version](https://camo.githubusercontent.com/98e0aaac25ce6e0605c09cef166f478e34bf00830901f527cec5de6cb4cd8e19/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f657363617065722f76)](https://packagist.org/packages/initphp/escaper) [![Total Downloads](https://camo.githubusercontent.com/1c9d39f50eb037231feb3b8020bbf886d9653c3e52b8d2ce178b294218eb2f6c/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f657363617065722f646f776e6c6f616473)](https://packagist.org/packages/initphp/escaper) [![Latest Unstable Version](https://camo.githubusercontent.com/bb25a4819ef44b3a0c7852d9e0c9754cf793d415755f218c11e578250a4c8f9d/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f657363617065722f762f756e737461626c65)](https://packagist.org/packages/initphp/escaper) [![License](https://camo.githubusercontent.com/90b1f5ee2677c6691d257af29e24235f5764c03fdecfa07b59a14eebe8f40693/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f657363617065722f6c6963656e7365)](https://packagist.org/packages/initphp/escaper) [![PHP Version Require](https://camo.githubusercontent.com/3372f3054b74ea2fc493e9161da42133b7abad819c728cdf681d37e3584c5358/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f657363617065722f726571756972652f706870)](https://packagist.org/packages/initphp/escaper)

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- PHP *CType* Extension
- PHP *MB\_String* or *Iconv* Extension

Installation
------------

[](#installation)

```
composer require initphp/escaper
```

Usage
-----

[](#usage)

`\InitPHP\Escaper\Esc::esc()` :

```
public static function esc(string[]|string $data, string $context = 'html', ?string $encoding = null): array|string;
```

- `$data` : The content to be cleared.
- `$context` : The method to be used for cleaning. If the value is not one of the following; Throws `Exception`.
    - `html`
    - `js`
    - `css`
    - `url`
    - `attr`
- `$encoding` : If the character set to be used is not specified or `NULL`; `UTF-8` is used by default.

`html` Escaper Example :

```

    Encodings set correctly!
