开发者

Implement Dots After a Certain Limit [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Truncate a multibyte String to n chars

Hye guys,

So here's what I need to do. I want dots to appears after a sentence crosses a certain number of words in PHP.

Ex - This is a lazy brown fox.

Now if the words are more than 7 chars -

开发者_运维百科

it should be like

This is..


$txt = "test1 test2 test3 test4 test5 test6 test7";
$txtArr = explode(" ",$txt);
$cut = 3;//cut after 3 words

$txtArr[$cut] = "...";
$arrReady = (array_slice($txtArr,0,$cut+1));

print implode(" ",$arrReady);

OR Characters:

$text = "some words test lala papa";
print substr($text,0,20)."...";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜