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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
9ggadmin
Forum Newbie
Posts: 2
Joined: Sat Jan 26, 2008 11:32 pm

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

Post 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:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

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

Post 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.
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

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

Post by jimthunderbird »

User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

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

Post by jimthunderbird »

Also, if you are interested, read drupal's search module's source code, you will find some goodies.
9ggadmin
Forum Newbie
Posts: 2
Joined: Sat Jan 26, 2008 11:32 pm

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

Post by 9ggadmin »

Thank you guys.
Post Reply