如何限制 php 描述中的字数?
how to limit number of words in a description in php?
我想用有限的字数显示一个简短的介绍,如果太长的话不剪切最后一个字...
我知道有一个 php 函数 substr() 但它不像 "this is my starting text..." 那样显示简介
它在 PHP 中显示 "this is my starting t..."。
谢谢你的回答。
<a href="#">'.substr($rows['title'],0,50).'</a>
为什么不是这个:
implode(' ', array_slice(explode(' ', $rows['title']), 0, 50));
- 炸开所有的单词;
- 获得前 50 个;
- 重新创建仅包含前 50 个单词的句子;
我想用有限的字数显示一个简短的介绍,如果太长的话不剪切最后一个字... 我知道有一个 php 函数 substr() 但它不像 "this is my starting text..." 那样显示简介 它在 PHP 中显示 "this is my starting t..."。 谢谢你的回答。
<a href="#">'.substr($rows['title'],0,50).'</a>
为什么不是这个:
implode(' ', array_slice(explode(' ', $rows['title']), 0, 50));
- 炸开所有的单词;
- 获得前 50 个;
- 重新创建仅包含前 50 个单词的句子;