Implement Dots After a Certain Limit [duplicate]
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)."...";
精彩评论