PHPackages                             hartpableo/php-censoring-tool - 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. hartpableo/php-censoring-tool

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

hartpableo/php-censoring-tool
=============================

A simple PHP censoring tool to hide emails and links in a text.

v1.0.1(today)00MITPHPPHP &gt;=8.0CI passing

Since Jun 20Pushed today1 watchersCompare

[ Source](https://github.com/hartpableo/php-censoring-tool)[ Packagist](https://packagist.org/packages/hartpableo/php-censoring-tool)[ RSS](/packages/hartpableo-php-censoring-tool/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

PHP Censoring Tool
==================

[](#php-censoring-tool)

A lightweight, flexible PHP library to censor email addresses and hyperlinks in block text. Ideal for cleaning user-generated content, masking database outputs, or protecting private information before displaying it publicly.

Features
--------

[](#features)

- **Email Censoring**: Matches and obscures standard email addresses.
- **Link Censoring**: Identifies HTML anchor tags (`...`) and obscures either the anchor text or the full tag.
- **Flexible Masking**: Decoupled design allows you to define custom replacement formats (e.g., HTML, markdown, custom text like `[REDACTED]`, or simple asterisks).
- **Zero Production Dependencies**: Light codebase that runs out-of-the-box on PHP 8.0 or newer.

---

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

[](#installation)

Install the package via Composer:

```
composer require hartpableo/php-censoring-tool
```

---

Usage
-----

[](#usage)

### 1. Basic Usage (Default HTML Output)

[](#1-basic-usage-default-html-output)

By default, censored links and emails are replaced with standard HTML tags styled with the class `.censored-text` and carrying a notice.

```
use HartPableo\PhpCensoringTool\Censor;

$text = "Contact support@example.com or visit Example Site.";

$censor = new Censor($text, "Please upgrade your subscription to view contact details.");
$output = $censor->getCensoredText();

echo $output;
// Contact ******************* or visit ************.
```

### 2. Advanced Usage (Custom Formatting Callback)

[](#2-advanced-usage-custom-formatting-callback)

If you need a plain text output, Markdown formatting, or custom redacted strings, you can pass a custom formatter as the third argument to the constructor:

```
use HartPableo\PhpCensoringTool\Censor;

$text = "Send your CV to jobs@example.com.";

// Censor using a simple '[REDACTED]' string:
$censor = new Censor($text, 'Redacted', function(string $string) {
    return '[REDACTED]';
});

echo $censor->getCensoredText();
// Send your CV to [REDACTED].
```

Another example using custom asterisk replacement:

```
$censor = new Censor($text, '', function(string $string) {
    return str_repeat('*', strlen($string));
});
```

---

Testing
-------

[](#testing)

### Automated Unit Tests

[](#automated-unit-tests)

The library includes a PHPUnit test suite. To run the automated unit tests:

1. Install development dependencies: ```
    composer install
    ```
2. Run the test suite: ```
    vendor/bin/phpunit
    ```

### Manual Sample Run

[](#manual-sample-run)

You can also run the quick demonstration script:

```
php tests/index.php
```

---

License
-------

[](#license)

This project is open-source software licensed under the [MIT License](LICENSE).

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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 ~0 days

Total

2

Last Release

0d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.4

v1.0.1PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/84109447?v=4)[Hart Lorenzo S. Pableo](/maintainers/hartpableo)[@hartpableo](https://github.com/hartpableo)

---

Top Contributors

[![hartpableo](https://avatars.githubusercontent.com/u/84109447?v=4)](https://github.com/hartpableo "hartpableo (8 commits)")

---

Tags

privacycensoremail-censorlink-censor

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hartpableo-php-censoring-tool/health.svg)

```
[![Health](https://phpackages.com/badges/hartpableo-php-censoring-tool/health.svg)](https://phpackages.com/packages/hartpableo-php-censoring-tool)
```

###  Alternatives

[statikbe/laravel-cookie-consent

Cookie consent modal for EU

219416.5k](/packages/statikbe-laravel-cookie-consent)[opengento/module-gdpr

Gdpr Compliance Module for Magento 2

14584.6k](/packages/opengento-module-gdpr)[georgringer/gdpr

Make TYPO3 more compatible to GDPR

4557.6k](/packages/georgringer-gdpr)[swearjar/swearjar

Profanity detection lib

14158.0k1](/packages/swearjar-swearjar)[bizley/cookiemonster

Yii extension to manage cookie warning.

1922.4k1](/packages/bizley-cookiemonster)

PHPackages © 2026

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