PHPackages                             bayfrontmedia/php-sanitize - 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. [Search &amp; Filtering](/categories/search)
4. /
5. bayfrontmedia/php-sanitize

ActiveLibrary[Search &amp; Filtering](/categories/search)

bayfrontmedia/php-sanitize
==========================

Simple class used to sanitize, filter and cast data.

v2.1.2(10mo ago)41.5k↑650%13MITPHPPHP ^8.0

Since Jul 27Pushed 10mo agoCompare

[ Source](https://github.com/bayfrontmedia/php-sanitize)[ Packagist](https://packagist.org/packages/bayfrontmedia/php-sanitize)[ Docs](https://github.com/bayfrontmedia/php-sanitize)[ RSS](/packages/bayfrontmedia-php-sanitize/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)DependenciesVersions (6)Used By (3)

PHP sanitize
------------

[](#php-sanitize)

Simple class used to sanitize, filter and cast data.

- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

License
-------

[](#license)

This project is open source and available under the [MIT License](LICENSE).

Author
------

[](#author)

[![Bayfront Media](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)

- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)

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

[](#requirements)

- PHP `^8.0` (Tested up to `8.4`)

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

[](#installation)

```
composer require bayfrontmedia/php-sanitize

```

Usage
-----

[](#usage)

- [cast](#cast)
- [email](#email)
- [url](#url)
- [path](#path)
- [escape](#escape)

---

### cast

[](#cast)

**Description:**

Ensures a given variable will be returned as a specific type. Defaults to "string".

**Parameters:**

- `$var` (mixed)
- `$type = self::CAST_STRING` (string): Any `CAST_*` constant

Valid cast types are available as the following constants:

- `CAST_ARRAY`: array
- `CAST_BOOL`: bool
- `CAST_FLOAT`: float
- `CAST_INT`: int
- `CAST_OBJECT`: object
- `CAST_STRING`: string

**Returns:**

- (mixed)

**Example:**

```
use Bayfront\Sanitize\Sanitize;

$input = '1.42';

echo Sanitize::cast($input, Sanitize::CAST_FLOAT);

```

---

### email

[](#email)

**Description:**

Filters string for valid email characters.

**Parameters:**

- `$email` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\Sanitize\Sanitize;

echo Sanitize::email('email@example.com');

```

---

### url

[](#url)

**Description:**

Filters string for valid URL characters.

**Parameters:**

- `$url` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\Sanitize\Sanitize;

echo Sanitize::url('https://www.example.com);

```

---

### path

[](#path)

**Description:**

Filters string for valid path syntax, with optional trailing slash.

This method removes any whitespace, spaces, and leading slashes. It will also convert reverse and multiple slashes to one single forward slash.

**Parameters:**

- `$path` (string)
- `$trailing = true` (bool): Require trailing slash

**Returns:**

- (string)

**Example:**

```
use Bayfront\Sanitize\Sanitize;

$path = '/some/ bad//path';

echo Sanitize::path($path);

```

---

### escape

[](#escape)

**Description:**

Escape strings and arrays. Other data types return their original value.

**NOTE:** Use caution when escaping entire arrays, as strings should typically only be escaped when outputting to HTML.

See:

**Parameters:**

- `$value` (mixed)
- `$encoding = 'UTF-8'` (string)

**Returns:**

- (mixed)

**Example:**

```
use Bayfront\Sanitize\Sanitize;

$html = 'Hyperlink';

echo Sanitize::escape($html);

```

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance56

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~446 days

Total

5

Last Release

326d ago

Major Versions

1.0.0 → v2.0.02023-01-26

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad62c8d0e69358fd63b16fdaa71d5359231cd0cf660bbc3419071dc705c63a8?d=identicon)[bayfrontmedia](/maintainers/bayfrontmedia)

---

Top Contributors

[![robinsonjohn](https://avatars.githubusercontent.com/u/24327848?v=4)](https://github.com/robinsonjohn "robinsonjohn (11 commits)")

---

Tags

castescapefilterphpsanitizexssphpfilterxssEscapesanitizecast

### Embed Badge

![Health badge](/badges/bayfrontmedia-php-sanitize/health.svg)

```
[![Health](https://phpackages.com/badges/bayfrontmedia-php-sanitize/health.svg)](https://phpackages.com/packages/bayfrontmedia-php-sanitize)
```

###  Alternatives

[htmlawed/htmlawed

Official htmLawed PHP library for HTML filtering

401.1M9](/packages/htmlawed-htmlawed)[aura/filter

Filters to validate and sanitize objects and arrays.

173561.0k10](/packages/aura-filter)[soosyze/kses

An HTML/XHTML filter written in PHP. Checks on attribute values. Can be used to avoid Cross-Site Scripting (XSS), Buffer Overflows and Denial of Service attacks, among other things.

1258.5k1](/packages/soosyze-kses)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
