PHPackages                             philiprehberger/php-mask - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. philiprehberger/php-mask

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

philiprehberger/php-mask
========================

Mask sensitive data in strings, arrays, and objects for safe logging

v1.2.0(2mo ago)138MITPHPPHP ^8.2CI passing

Since Mar 15Pushed 1mo agoCompare

[ Source](https://github.com/philiprehberger/php-mask)[ Packagist](https://packagist.org/packages/philiprehberger/php-mask)[ Docs](https://github.com/philiprehberger/php-mask)[ GitHub Sponsors](https://github.com/philiprehberger)[ RSS](/packages/philiprehberger-php-mask/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (6)Versions (9)Used By (0)

PHP Mask
========

[](#php-mask)

[![Tests](https://github.com/philiprehberger/php-mask/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-mask/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/5767d1db3ac7a2f03c0c102c99c024d7a336ccb746e21ecb81da3dac65ddcd8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d6d61736b2e737667)](https://packagist.org/packages/philiprehberger/php-mask)[![Last updated](https://camo.githubusercontent.com/7a4f33b6f586e04358971f6273c009d575745442fa27b5c9d7c99b5c4d60f2cf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7068696c69707265686265726765722f7068702d6d61736b)](https://github.com/philiprehberger/php-mask/commits/main)

Mask sensitive data in strings, arrays, and objects for safe logging.

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

[](#requirements)

- PHP 8.2+

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

[](#installation)

```
composer require philiprehberger/php-mask
```

Usage
-----

[](#usage)

### Email masking

[](#email-masking)

```
use PhilipRehberger\Mask\Mask;

Mask::email('john@example.com');
// "j***@e******.com"
```

### Phone masking

[](#phone-masking)

```
Mask::phone('+1-555-123-4567');
// "+1-555-***-4567"
```

### Credit card masking

[](#credit-card-masking)

```
Mask::creditCard('4111 1234 5678 1111');
// "4111 **** **** 1111"
```

### IP address masking

[](#ip-address-masking)

```
Mask::ip('192.168.1.100');
// "192.168.*.*"
```

### IBAN masking

[](#iban-masking)

```
Mask::iban('DE89370400440532013000');
// "DE****************3000"

Mask::iban('GB29NWBK60161331926789', '#');
// "GB################6789"
```

### Custom masking

[](#custom-masking)

```
Mask::custom('SensitiveData', visibleStart: 3, visibleEnd: 3);
// "Sen*******ata"

Mask::custom('SensitiveData', visibleStart: 0, visibleEnd: 0);
// "*************"
```

### URL masking

[](#url-masking)

```
Mask::url('https://user:pass@example.com/path?token=abc123&key=secret');
// "https://u***:p***@example.com/path?token=a*****&key=s*****"

Mask::url('https://example.com/search?q=test');
// "https://example.com/search?q=t***"
```

### JWT masking

[](#jwt-masking)

```
Mask::jwt('eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.SflKxwRJSMeKKF2QT4fwpM');
// "eyJhbGciOiJIUzI1NiJ9.[MASKED].[MASKED]"
```

### Generic string masking

[](#generic-string-masking)

```
Mask::string('SensitiveData');
// "Se*********ta"

Mask::string('SensitiveData', visibleStart: 3, visibleEnd: 3);
// "Sen*******ata"
```

### Recursive array masking with dot notation

[](#recursive-array-masking-with-dot-notation)

```
$data = [
    'user' => [
        'name' => 'John',
        'address' => [
            'street' => '123 Main St',
        ],
    ],
    'password' => 'secret123',
];

Mask::arrayRecursive($data, ['password', 'user.address.street']);
// ['user' => ['name' => 'John', 'address' => ['street' => '12*******St']], 'password' => 'se*****23']
```

### Array masking (deep)

[](#array-masking-deep)

```
$data = [
    'name' => 'John',
    'email' => 'john@example.com',
    'nested' => [
        'ssn' => '123-45-6789',
    ],
];

Mask::array($data, ['email', 'ssn']);
// ['name' => 'John', 'email' => 'jo************om', 'nested' => ['ssn' => '12*******89']]
```

### JSON masking

[](#json-masking)

```
$json = '{"name":"John","ssn":"123-45-6789"}';

Mask::json($json, ['ssn']);
// '{"name":"John","ssn":"12*******89"}'
```

### Redaction policies

[](#redaction-policies)

```
use PhilipRehberger\Mask\RedactionPolicy;

$policy = RedactionPolicy::create()
    ->maskField('user.email', 'email')
    ->maskField('*.secret', 'full')
    ->maskPattern('/password|token/i', 'full');

$data = [
    'user' => ['name' => 'John', 'email' => 'john@example.com'],
    'service' => ['secret' => 'sk-12345'],
    'password' => 'hunter2',
];

$result = $policy->apply($data);
// ['user' => ['name' => 'John', 'email' => 'j***@e******.com'],
//  'service' => ['secret' => '********'],
//  'password' => '*******']
```

### Custom configuration

[](#custom-configuration)

```
use PhilipRehberger\Mask\MaskConfig;

Mask::configure(new MaskConfig(
    maskChar: '#',
    preserveLength: false,
    visibleStart: 3,
    visibleEnd: 3,
));

Mask::string('SensitiveData');
// "Sen###ata"
```

API
---

[](#api)

MethodDescription`Mask::email(string $email): string`Mask an email address, preserving first char of local/domain and TLD`Mask::phone(string $phone): string`Mask a phone number, preserving country code and last 4 digits`Mask::creditCard(string $number): string`Mask a credit card, showing first 4 and last 4 digits`Mask::ip(string $ip): string`Mask an IP address, showing first two octets (v4) or groups (v6)`Mask::iban(string $value, string $char = '*'): string`Mask an IBAN, showing country code and last 4 characters`Mask::custom(string $value, int $visibleStart, int $visibleEnd, string $char = '*'): string`Mask a string with configurable visible start/end lengths`Mask::url(string $url): string`Mask URL query parameter values and embedded credentials`Mask::jwt(string $token): string`Mask JWT payload and signature, preserving header`Mask::string(string $value, int $visibleStart = 2, int $visibleEnd = 2): string`Mask a generic string with configurable visible characters`Mask::arrayRecursive(array $data, array $keys, string $char = '*'): array`Recursively mask values at specified keys, supporting dot notation paths`Mask::array(array $data, array $keys): array`Deep-mask specified keys in an associative array`Mask::json(string $json, array $keys): string`Parse JSON, mask specified keys, re-encode`Mask::configure(MaskConfig $config): void`Set global masking configuration`Mask::resetConfig(): void`Reset configuration to defaults`RedactionPolicy::create(): self`Create a new redaction policy`RedactionPolicy::maskField(string $path, string $method): self`Register a masking rule for a field path (dot notation, wildcards)`RedactionPolicy::maskPattern(string $regex, string $method): self`Register a pattern-based rule matched against field names`RedactionPolicy::apply(array $data): array`Apply all rules to an array, returning masked copy`RedactionPolicy::merge(self $other): self`Merge another policy into this oneDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

Support
-------

[](#support)

If you find this project useful:

⭐ [Star the repo](https://github.com/philiprehberger/php-mask)

🐛 [Report issues](https://github.com/philiprehberger/php-mask/issues?q=is%3Aissue+is%3Aopen+label%3Abug)

💡 [Suggest features](https://github.com/philiprehberger/php-mask/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)

❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)

🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)

💻 [GitHub Profile](https://github.com/philiprehberger)

🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance88

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.9% 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 ~2 days

Total

8

Last Release

85d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

loggingsanitizesensitiveprivacymaskredact

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-php-mask/health.svg)

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

###  Alternatives

[monolog/monolog

Sends your logs to files, sockets, inboxes, databases and various web services

21.4k997.8M7.9k](/packages/monolog-monolog)[symfony/monolog-bundle

Symfony MonologBundle

2.9k258.2M1.7k](/packages/symfony-monolog-bundle)[itsgoingd/clockwork

php dev tools in your browser

5.9k29.0M110](/packages/itsgoingd-clockwork)[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k240.0M314](/packages/sentry-sentry)[sentry/sentry-laravel

Laravel SDK for Sentry (https://sentry.io)

1.3k122.6M185](/packages/sentry-sentry-laravel)[sentry/sentry-symfony

Symfony integration for Sentry (http://getsentry.com)

73764.5M84](/packages/sentry-sentry-symfony)

PHPackages © 2026

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