Answer the question
In order to leave comments, you need to log in
php yii2 text output and formatting?
Hello, I'm making a blog for educational purposes and ran into a problem with the output of the text of the posts. I have formatted text in each post (paragraph tags, they have their own classes), but it is stored in the database as plain text. Writing tags with classes to the database is probably a bad idea. Even on the page of a particular post, pictures can be inserted in different places (on some pages there are no pictures at all). Keeping img tags in the database is also probably a bad option. What are some good solutions to these problems?
Answer the question
In order to leave comments, you need to log in
Keep like this - Common practice. To output, use something like this:
HTML purifier
<?= Yii::$app->formatter->asHtml($model->content, [
'Attr.AllowedRel' => ['nofollow'],
'HTML.SafeObject' => true,
'Output.FlashCompat' => true,
'HTML.SafeIframe' => true,
'AutoFormat.AutoParagraph' => true,
'URI.SafeIframeRegexp' => '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%',
]) ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question