本文整理汇总了PHP中Str::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::truncate方法的具体用法?PHP Str::truncate怎么用?PHP Str::truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Str
的用法示例。
在下文中一共展示了Str::truncate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_truncate
/**
* Test for Str::truncate()
*
* @test
*/
public function test_truncate()
{
$limit = 15;
$string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
$output = Str::truncate($string, $limit);
$expected = 'Lorem ipsum dol...';
$this->assertEquals($expected, $output);
$output = Str::truncate($string, $limit, '..');
$expected = 'Lorem ipsum dol..';
$this->assertEquals($expected, $output);
$string = '<h1>' . $string . '</h1>';
$output = Str::truncate($string, $limit, '...', false);
$expected = '<h1>Lorem ipsum...';
$this->assertEquals($expected, $output);
$output = Str::truncate($string, $limit, '...', true);
$expected = '<h1>Lorem ipsum dol...</h1>';
$this->assertEquals($expected, $output);
}
示例2: test_truncate_multiple_tags
/**
* Test for Str::truncate()
*
* @test
* @dataProvider truncate_provider
*/
public function test_truncate_multiple_tags($limit, $string)
{
$limit = 400;
$string = '<p><strong>' . $string . '</strong></p>';
$output = Str::truncate($string, $limit, '...', true);
$this->assertEquals($string, $output);
}
示例3:
<a href="#" class="clearfix">
<img src="<?php
echo $value->from->people->photo;
?>
" class="msg-photo" alt="<?php
echo $value->from->people->nickname;
?>
Avatar" />
<span class="msg-body">
<span class="msg-title">
<span class="blue"><?php
echo $value->from->people->nickname;
?>
:</span>
<?php
echo \Str::truncate($value->body, 0, 21, '...');
?>
</span>
<span class="msg-time">
<i class="ace-icon fa fa-clock-o"></i>
<span><?php
echo \Date::time_ago($value->created_at);
?>
</span>
</span>
</span>
</a>
</li>
<?php
}
示例4: date
</span>
<p><?php
echo date('d', $date);
?>
</p>
</div>
<div class="events__title">
<h5>
<? if(\Arr::get($config, 'link')) :?>
<a href="<?php
echo \Arr::get($config, 'link') . '?month=' . date('M', $date) . '#' . $event->id;
?>
">
<? endif;?>
<?php
echo \Str::truncate($event->name, 30, '...');
?>
<? if(\Arr::get($config, 'link')) :?>
</a>
<? endif;?>
</h5>
</div>
</div>
</a>
<? $i++;?>
<? endif ?>
示例5: __
?>
</h1>
<p>
<small>
<?php
echo __('by');
?>
<a href="<?php
echo \Router::get('show_post_author', array('author' => $post->user->username));
?>
">
<?php
echo $post->user->username;
?>
</a> <?php
echo __('on');
?>
<em><?php
echo date('d/m/Y', $post->created_at);
?>
</em>
</small>
</p>
</div>
<graph></graph>
<?php
echo $snippet == true ? \Str::truncate(\Markdown::parse($post->content), \Config::get('application.truncate', 400)) : \Markdown::parse($post->content);
?>
</article>
示例6: array
?>
" >
<small>
<a href="<?php
echo \Router::get('show_post_category', array('category' => $post->category->slug));
?>
"><?php
echo $post->category->name;
?>
</a>
</small>
<a href="<?php
echo \Router::get('show_post', array('segment' => $post->slug));
?>
" >
<h2 class=""><?php
echo \Str::truncate($post->name, \Config::get('application.truncate', 50));
?>
</h2>
</a>
</article>
<?php
}
?>
</div>
<?php
}
示例7: if
echo \Arr::get($region, 'title');
?>
" class="scale-with-grid">
<h5><?php
echo \Arr::get($region, 'title', 'Default');
?>
</h5>
<? $content = \Arr::get( $region, 'content', 'Default content, please add your own.' ); ?>
<? if ( is_string ( $content ) ) : ?>
<p>
<?php
echo \Str::truncate($content, 200, '...');
?>
</p>
<? elseif ( is_array ( $content ) ) : ?>
<? foreach ( $content as $line ) : ?>
<p>
<?php
echo $line;
?>
</p>
<? endforeach; ?>
示例8:
$thumbnail = '/assets/web/images/01.jpg';
$title = '';
if (in_array($item->order_type, ['SELL', 'GROUPBUY'])) {
$thumbnail = $detail->goods->thumbnail;
$title = $detail->goods->title;
} else {
if ($item->order_type == 'MARKET') {
$thumbnail = $detail->market->thumbnail;
$title = $detail->market->title ? $detail->market->title : $detail->goods->title;
} else {
if ($item->order_type == 'RESERVE') {
$title = "{$detail->table->name}({$detail->seat->name})";
}
}
}
$title = \Str::truncate($title, 25, '...');
?>
<img src="<?php
echo $thumbnail;
?>
" alt="" style="width: 100%;">
</div>
<div class="col-xs-8" style="border-bottom: 1px solid #efefef;">
<p style=" padding-top: 10px;"><?php
echo $title;
?>
</p>
<?php
if ($item->order_type == 'MARKET') {
?>
<p style=" height: 50px; overflow: auto;">夺宝号码:<?php
示例9: array
<article class="post featured-story">
<a href="<?php
echo \Router::get('show_post', array('segment' => $post->slug));
?>
">
<h1><?php
echo $post->name;
?>
</h1>
<img class="img-responsive" src="<?php
echo $featured_image;
?>
" alt=""/>
<p>
<?php
echo \Str::truncate($post->content, 400, ' <span class="primary-text">…continue reading</span>');
?>
</p>
</a>
</article>
示例10: foreach
<?php
foreach ($items as $item) {
?>
<div class="sort-wrapper">
<label class="sort-check">
<?php
echo \Form::checkbox('ids[]', $item->id);
?>
</label>
<div class="aucid"><?php
echo $item->auc_id;
?>
</div>
<div class="title"><?php
echo Str::truncate($item->title, 25);
?>
</div>
<div class="price"><?php
echo $item->price;
?>
</div>
<div class="date"><?php
echo Date::create_from_string($item->won_date, 'mysql')->format('display_date');
?>
</div>
<div class="vendor"><?php
echo $item->vendor->name;
?>
</div>
<div class="action">
示例11:
?>
<div class="list-group-item">
<div class="row">
<div class="col-xs-4" style="padding-left: 2px; padding-right: 0px;">
<img src="<?php
echo $detail->goods->thumbnail;
?>
" alt="<?php
echo $detail->goods->title;
?>
" style="width: 100%; height: 100%;"/>
</div>
<div class="col-xs-8">
<dl style="margin-top: 0px; margin-bottom: 0px;">
<dt><?php
echo \Str::truncate($detail->goods->title, 25, '...');
?>
</dt>
<dd>数量: <?php
echo $detail->num;
?>
<span style="padding-left: 5px">单价: <?php
echo $detail->price;
?>
</span></dd>
</dl>
</div>
</div>
</div>
<?php
}
示例12: testTruncate
public function testTruncate()
{
$str = Str::truncate('abcdefghij', 5);
$this->assertEquals($str, 'ab...');
}
示例13:
<tr>
<td><?php
echo Date::forge($item->created_at)->format('mysql');
?>
</td>
<td><?php
echo $item->name;
?>
</td>
<td><?php
echo $item->email;
?>
</td>
<td><?php
echo Str::truncate($item->comment, 50, '...', true);
?>
</td>
<td><?php
echo $item->ip_address;
?>
</td>
<td>
<?php
echo Html::anchor('admin/form/view/' . $item->id, '表示');
?>
</td>
</tr>
<?php
}
示例14: foreach
foreach ($posts as $post) {
?>
<article id="post-<?php
echo $post->id;
?>
" class="post-preview">
<a href="<?php
echo \Router::get('show_post', array('segment' => $post->slug));
?>
" >
<h2><?php
echo $post->name;
?>
</h2>
<p><?php
echo \Str::truncate(\Markdown::parse($post->content), \Config::get('application.truncate', 600));
?>
</p>
</a>
<small>
<a href="<?php
echo \Router::get('show_post_category', array('category' => $post->category->slug));
?>
"><?php
echo $post->category->name;
?>
</a>,
<?php
echo __('by');
?>
<a href="<?php
示例15: limit_chars
/**
* Limit a text to a given characters.
* Alias of \Str:truncate(), with configurable parameters
*
* @access public
* @static
* @param string $str: phrase to limit characters of
* @param array $args (default: array()):
* "length": number of characters to keep;
* "trail": ommission string
* @return string
*/
public static function limit_chars($string, $args = array())
{
self::extend($args, __FUNCTION__);
return \Str::truncate($string, $args['length'], $args['trail']);
}