1

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..

Community
  • 1
  • 1
sarthak
  • 11
  • 2

1 Answers1

1
$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)."...";
fatnjazzy
  • 6,070
  • 12
  • 57
  • 83