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

2

1 Answer 1

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)."..."; 
Sign up to request clarification or add additional context in comments.

2 Comments

works pefectly, but I don't want it to cut after three words...I want it to cut after 20 characters. Is that possible?
@sarthak - I edit my post, please click on the V near my answer if it helps you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.