Page 1 of 1

Shorten long sentences and end the summary with '...'?

Posted: Sat Jan 26, 2008 11:35 pm
by 9ggadmin
I have a script that posts forum topics into a smaller area on the front page of 9thgategames.com .

Some of the forum posts though are too large to fit in the area I want them in.

How can I get a limited amount of characters to show and then end the summary with '...'? :banghead:

Re: Shorten long sentences and end the summary with '...'?

Posted: Sat Jan 26, 2008 11:46 pm
by John Cartwright
Two ways:

The simplest way is to do a $text = substr($text, 0, 200) .' ... '

Although you will find this will capture the first 200 characters, however sometime this will produce chopped up words. Instead, a more elegant solution:
Useful Posts wrote:
EDIT | If it's coming from your database, indeed perform the substr on the database side.

Re: Shorten long sentences and end the summary with '...'?

Posted: Sat Jan 26, 2008 11:47 pm
by jimthunderbird

Re: Shorten long sentences and end the summary with '...'?

Posted: Sat Jan 26, 2008 11:48 pm
by jimthunderbird
Also, if you are interested, read drupal's search module's source code, you will find some goodies.

Re: Shorten long sentences and end the summary with '...'?

Posted: Sat Jan 26, 2008 11:50 pm
by 9ggadmin
Thank you guys.