truncate() public static method

Truncates a string to the number of characters specified.
public static truncate ( string $string, integer $length, string $suffix = '...', string $encoding = null, boolean $asHtml = false ) : string
$string string The string to truncate.
$length integer How many characters from original string to include into truncated string.
$suffix string String to append to the end of truncated string.
$encoding string The charset to use, defaults to charset currently used by application.
$asHtml boolean Whether to treat the string being truncated as HTML and preserve proper HTML tags. This parameter is available since version 2.0.1.
return string the truncated string.
Beispiel #1
1
		<!-- Left col -->
		<div class="col-lg-6">
		  <!-- Custom tabs (Charts with tabs)-->
		  <div class="box box-info">
			<div class="box-header with-border">
			  <h3 class="box-title">Top URI Request</h3>
			</div><!-- /.box-header -->
			<div class="box-body">
			  <div class="row">
				<div class="col-md-11">
					<?php 
Pjax::begin();
?>
					<?php 
echo GridView::widget(['dataProvider' => $dataProviderApi, 'filterModel' => $searchModelApi, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'uri_access', 'value' => function ($model) {
    return BaseStringHelper::truncate($model->uri_access, 45, ' ... ', null, true);
}], 'count']]);
?>
					<?php 
Pjax::end();
?>
				</div>
			  </div><!-- /.row -->
			</div><!-- /.box-body -->
		  </div><!-- /.box -->
		</div><!-- /.Left col -->
		<div class="col-lg-6">
		  <!-- Custom tabs (Charts with tabs)-->
		  <div class="box box-info">
			<div class="box-header with-border">
			  <h3 class="box-title">Used IP Address</h3>
Beispiel #2
0
 public function beforeSave($insert)
 {
     if ($this->isNewRecord) {
         //generate & upload
         $this->string = substr(uniqid('img'), 0, 12);
         //imgRandomString
         $this->image = UploadedFile::getInstance($this, 'img');
         $this->filename = 'static/images/' . $this->string . '.' . $this->image->extension;
         $this->image->saveAs($this->filename);
         $this->text_preview = BaseStringHelper::truncate($this->text, 250, '...');
         //save
         $this->img = '/' . $this->filename;
     } else {
         $this->image = UploadedFile::getInstance($this, 'img');
         if ($this->image) {
             $this->image->saveAs(substr($this->img, 1));
         }
     }
     return parent::beforeSave($insert);
 }
Beispiel #3
0
<?php

use yii\helpers\Html;
use yii\helpers\BaseStringHelper;
?>

<li><?php 
echo Html::a(BaseStringHelper::truncate(strip_tags($itemValue['name']), $itemParams['trim'], $itemParams['trimEnding']), $itemParams['controller'] . $itemValue['slug']);
?>
</li>
Beispiel #4
0
<h2>
    <a href="<?php 
echo $urlHead . $item->slug;
?>
"><?php 
echo $item->name;
?>
</a>
</h2>
<hr>
<?php 
echo $imageBlock;
?>
<p><?php 
echo BaseStringHelper::truncate(strip_tags($item->text), $textTruncate, "...");
?>
</p>
<a class="<?php 
echo $classMore;
?>
" href="<?php 
echo $urlHead . $item->slug;
?>
"><?php 
echo $captionMore;
?>
</a>

<hr>
Beispiel #5
0
    </div>
    <!-- /.row -->
    <?php 
$model = new Content();
//    $items = $model->bySection(5, $perPage);
$lenghtLimit = 720;
$out = '';
if (!empty($models)) {
    foreach ($models as $item) {
        $images = ContentHelper::fetchImages($item['text']);
        $cleanContent = ContentHelper::cleanImages($item['text']);
        $header = '<h3><a href="/info/' . $item['slug'] . '" > ' . $item['name'] . '</a></h3>';
        $buttonMore = '';
        if (strlen($cleanContent) >= $lenghtLimit) {
            $buttonMore = '<a class="btn btn-info" href="/events/' . $item['slug'] . '"    style="float:right;" ><i>Докладніше</i></a>';
            $cleanContent = BaseStringHelper::truncate(strip_tags($cleanContent), $lenghtLimit, "...");
        }
        $content = '<p>' . $cleanContent . '</p>';
        if (!$images['count']) {
            $item = '<div class="col-md-12">' . $header . $content . $buttonMore . '</div>';
        } else {
            $item = '<div class="col-md-5"><a href="/info/' . $item['slug'] . '">
                    <img class="img-responsive img-hover" src="' . $images['main']['src'] . '" alt="' . $images['main']['alt'] . '">
                    </a></div><div class="col-md-7">' . $header . $content . $buttonMore . '</div>';
        }
        $out .= '<div class="row">' . $item . '</div><hr>';
    }
}
?>

    <?php 
Beispiel #6
0
<?php

use ut8ia\contentmodule\helpers\ContentHelper;
use yii\helpers\BaseStringHelper;
$images = ContentHelper::fetchImages($item->text);
$alt = isset($images['main']['alt']) ? $images['main']['alt'] : $item->name;
$image = '<img class="' . $imageClass . '" src="' . $images['main']['src'] . '" alt="' . $alt . '">';
$btClass = 12 / $numInRow;
echo '<div class="col-md-' . $btClass . ' img-portfolio">
            <a href="' . $urlHead . $item->slug . '">' . $image . '</a>
            <h3><a href="' . $urlHead . $item->slug . '">' . $item->name . '</a></h3>
            <p>' . BaseStringHelper::truncate(strip_tags($item->text), $textTruncate, "...") . '</p>
                </div>';
Beispiel #7
0
                    <input type="text" class="form-control">
                    <span class="input-group-btn">
                            <button class="btn btn-default" type="button"><i class="fa fa-search"></i></button>
                        </span>
                </div>
            </div>
            <div class="well">
                <h4>Інші події</h4>
                <div class="row">
                    <div class="col-lg-12">
                        <ul class="list-unstyled">
                            <?php 
if (!empty($latestPosts)) {
    $str = '';
    foreach ($latestPosts as $post) {
        $str .= '<li>' . Html::a(BaseStringHelper::truncate(strip_tags($post['name']), 40, "..."), '/info/' . $post['slug']) . '</li>';
    }
    echo '<ul>' . $str . '</ul>';
}
?>
                            </li>
                        </ul>
                    </div>
                </div>
                <!-- /.row -->
            </div>
        </div>
    </div>
    <!-- /.row -->

    <!-- Related Projects Row -->