【问题标题】:Laravel Limit Characters - PHP [duplicate]Laravel 限制字符 - PHP [重复]
【发布时间】:2016-03-23 01:02:39
【问题描述】:

我使用这行代码在我的应用中显示下一篇文章的标题

<span class="blog-title-next"> {{ $post->nextPost()['title'] }} </span>

如何将标题名称限制为仅显示前 10 个字符?

谢谢。

【问题讨论】:

标签: php html laravel laravel-blade


【解决方案1】:

您可以使用str_limit() 辅助函数:

{{ str_limit($post->nextPost()['title'], 10) }}

对于较新版本的 laravel

use Illuminate\Support\Str;

$truncated = Str::limit('The quick brown fox jumps over the lazy dog', 20, ' (...)');

// The quick brown fox (...)

【讨论】:

  • 你可以这样做 {{ str_limit($post->nextPost(), $limit = 150, $end = '...') }}
  • 你们节省时间.. (y)
猜你喜欢
  • 2020-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多