Laravel 限制字符 - PHP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34319716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:54:47  来源:igfitidea点击:

Laravel Limit Characters - PHP

phphtmllaravellaravel-blade

提问by Nikola

I used this line of code to show next post title on my app

我使用这行代码在我的应用程序上显示下一个帖子标题

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

How can I limit the title name to show only first 10 characters?

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

Thanks.

谢谢。

回答by Pantelis Peslis

You could use the str_limit()helper function:

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

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