Trim text to 340 chars

前端 未结 9 911
情深已故
情深已故 2021-02-07 14:21

I\'m pulling blog posts from a DB. I want to trim the text to a max length of 340 characters.

If the blog post is over 340 characters I want to trim the text to the las

9条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 15:01

    If you have the mbstring extension enabled (which is on most servers nowadays), you can use the mb_strimwidth function.

    echo mb_strimwidth($string, 0, 340, '...');
    

提交回复
热议问题