nedarta / yii2-clean-html-behavior
A Yii2 behavior to clean and sanitize HTML content in ActiveRecord attributes.
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- ezyang/htmlpurifier: ^4.13
- yiisoft/yii2: ~2.0.0
README
A Yii2 behavior to clean and sanitize HTML content in ActiveRecord attributes.
Installation
Install the extension via Composer:
composer require nedarta/yii2-clean-html-behavior
Usage
Add the behavior to your ActiveRecord model:
use nedarta\behaviors\CleanHtmlBehavior; public function behaviors() { return [ [ 'class' => CleanHtmlBehavior::class, 'attributes' => ['content', 'description'], 'htmlPurifierConfig' => [ 'HTML.Allowed' => 'p,b,i,u,ul,ol,li', ], 'keepEmoji' => true, // Set to true to preserve emoji characters ], ]; }
Configuration
-
attributes
: List of attributes to clean. -
htmlPurifierConfig
: Configuration for HtmlPurifier. -
keepEmoji
: Whether to preserve emoji characters. -
preserveLineBreaks
: Whether to preserve line breaks.
License
MIT