在Laravel 5.5中使用str_limit函数限制文本 [英] limit text using str_limit function in Laravel 5.5
问题描述
我一直试图用str_limit
限制我的博客内容文本,直到我对其施加字符数限制之前,该文本才可以正常工作.请查看我的刀片文件代码中缺少的内容:
I have been trying to limit my blog content text with str_limit
that works fine until I apply limit of characters on it. kindly see what is missing in the code of my blade file:
{!! str_limit($blog->content) !!}
在默认限制下可以正常工作,在视图上显示有限的文本.但是当我应用任何自定义限制(即{!! str_limit($blog->content, 20) !!}
时)不会在视图上显示任何文本.
{!! str_limit($blog->content) !!}
works fine with the default limit, showing limited text on the view. But when I apply any custom limit i.e. {!! str_limit($blog->content, 20) !!}
it do not show any text on the view.
推荐答案
已经使用{!! substr(strip_tags($blog->content), 0, 150) !!}
对其进行了分类,可以很好地满足我的要求.
Have sorted out this thing using {!! substr(strip_tags($blog->content), 0, 150) !!}
, works fine with what I was requiring.
这篇关于在Laravel 5.5中使用str_limit函数限制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!