Download the PHP package yasser-elgammal/pure-text without Composer
On this page you can find all versions of the php package yasser-elgammal/pure-text. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yasser-elgammal/pure-text
More information about yasser-elgammal/pure-text
Files in yasser-elgammal/pure-text
Package pure-text
Short Description A Laravel package for filtering and replacing inappropriate or unwanted words with support for Arabic and Unicode, multiple replacement strategies, Blade directives, middleware, and more.
License MIT
Homepage https://github.com/YasserElgammal/pure-text
Informations about the package pure-text
PureText
PureText is a Laravel package for filtering and replacing inappropriate or unwanted words within model attributes automatically. Designed to be customizable and efficient, PureText allows developers to specify filterable attributes for each model and handle multiple languages seamlessly — including Arabic and other Unicode languages, with built-in diacritics normalization, leetspeak detection, and whitelisting.
✨ Features
- Automatic Model Filtering — Apply the
PureTextFilterabletrait and bad words are filtered on save. - Whitelist / Allowed Words — Prevent false positives (the Scunthorpe problem) via global config or runtime whitelist.
- Arabic & Unicode Normalization — Automatically handles tashkeel (diacritics), tatweel (kashida), and letter variants (
أ/إ/آ -> ا,ة -> ه,ى -> ي). - Leetspeak & Homoglyph Evasion — Detects number and symbol substitutions such as
b4d,@ss,sh!t,p0rn,1337. - Multiple Replacement Strategies — Choose between
fixed,character, orlength_matchreplacements. - Facade —
PureText::filter(),PureText::containsBadWords(),PureText::getBadWords(),PureText::withWhitelist(). - Blade Directive —
@pureText($text)for templates. - Middleware — Filter request fields automatically via route middleware.
- Validation Rule —
pure_textrule for Laravel Validator with field-level whitelist support. - Helper Functions —
pure_text()andhas_bad_words()global helpers. - Events —
TextFilteredevent dispatched on model attribute filtering. - Customizable — Bring your own implementation via
TextFilterInterface.
📋 Requirements
- PHP 8.1+
- Laravel 10, 11, 12, or 13
📦 Installation
Install via Composer:
Publish the configuration file:
Configure your word list in config/badwords.php.
🚀 Usage
1. Automatic Model Filtering (Trait)
Add the PureTextFilterable trait to any model and define $filterable attributes:
Now, bad words are automatically replaced when saving:
2. Facade
3. Whitelist / Allowed Words (Preventing False Positives)
Avoid the classic Scunthorpe problem (e.g. flagging "cocktail" because of "cock").
PureText supports both global and runtime whitelisting:
4. Arabic & Unicode Normalization
PureText automatically handles Arabic diacritics (tashkeel), stretching (tatweel), and letter variants:
5. Leetspeak & Homoglyph Evasion
Catches evasion attempts that use numbers or symbols:
6. Blade Directive
7. Validation Rule
Use in form requests or validators. You can also pass field-level whitelisted words directly:
8. Middleware
Register in your route:
9. Helper Functions
⚙️ Configuration
After publishing, edit config/badwords.php:
Replacement Strategies
| Strategy | Input | Output | Description |
|---|---|---|---|
fixed |
badword |
*** |
Replaces with the replacement value |
character |
badword |
******* |
Each character replaced with character |
length_match |
badword |
******* |
First char of replacement repeated to match length |
🔌 Advanced: Custom Implementation
You can swap the filter service with your own by binding TextFilterInterface:
📡 Events
When a model attribute is filtered via the PureTextFilterable trait, a TextFiltered event is dispatched:
🧪 Testing
📄 Changelog
Please see CHANGELOG.md for recent changes.
🤝 Contributing
Contributions are welcome! Please fork this repository and submit a pull request for any improvements.
📜 License
The MIT License (MIT). Please see LICENSE for more information.
All versions of pure-text with dependencies
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/validation Version ^10.0|^11.0|^12.0|^13.0