/** * 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); }
/** * 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); }
<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 }
</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 ?>
?> </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>
?> " > <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 }
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; ?>
$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
<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>
<?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">
?> <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 }
public function testTruncate() { $str = Str::truncate('abcdefghij', 5); $this->assertEquals($str, 'ab...'); }
<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 }
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
/** * 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']); }
<?php foreach ($scraps as $scrap): ?> <div class="scrap"> <?php echo Html::anchor($scrap->short_id, Uri::create($scrap->short_id)); ?> - Created on <?php echo date('F j, Y \a\t g:i a', $scrap->created_at); ?> <div class="preview"><pre><code><?php echo Str::truncate($scrap->contents, 200, '...', true); ?></code></pre></div> </div> <?php endforeach; ?>
<ul class="nav navbar-right nav-pills"> <li><a ng-click="open('section-menu')"> Sections <span class="glyphicon glyphicon-th-list" aria-hidden="true"></span> </a></li> <?php if (isset($user_email)) { ?> <li role="presentation" class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><?php echo Str::truncate($user_email, 15); ?> <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="<?php echo \Router::get('backend_account'); ?> ">Account</a></li> <li><a href="<?php echo \Router::get('backend_account_save'); ?> ">Saved Items</a></li> <li class="divider"></li> <li><a href="#">Customer Service</a></li> <li><a href="#">Portfolio</a></li> <li><?php