<?php

namespace frontend\helpers;
use Yii;
use yii\helpers\BaseStringHelper;


class TextHelper extends BaseStringHelper
{
    public static function truncateHtmlText($string, $length, $suffix = '...', $encoding = null, $asHtml = false, $html = '<p></p>')
    {
        if ($asHtml) {
            return static::truncateHtml($string, $length, $suffix, $encoding ?: Yii::$app->charset);
        }

        if (mb_strlen($string, $encoding ?: Yii::$app->charset) > $length) {
            return  strip_tags(trim(mb_substr($string, 0, $length, $encoding ?: Yii::$app->charset)) . $suffix, $html);
        } else {
            return  strip_tags($string, $html);
        }


    }
}
