Purifier
Purifier copied to clipboard
How to save styles?
I want the database to remain in this form
<b>User, </b><div style="display: inline-block;"> Hello</div>
But after processing
$textComment = Purifier::clean($request->text, 'titles');
The style attribute is deleted.
<b>User, </b><div> Hello</div>
you can change its default configuration, its already mentioned here , you can do it
Edit:
you can change which attributes you would like to modify
so , if you want to have style attribute in your div tag , you can do it like div[style]
in 'HTML.Allowed , if you also want to allow any other attribute like data-attribute
you can do it as OR( |
) operator. div[style|data-attribute]
'default' => [
'HTML.Doctype' => 'HTML 4.01 Transitional',
'HTML.Allowed' => 'div[style],b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
'AutoFormat.AutoParagraph' => true,
'AutoFormat.RemoveEmpty' => true,
],