1

I have a page where i display all post coming from the database, I don't want to display all the contents just the excerpts from it. This is just easy i know, i could search the internet for it, but i don't know what you call it. Anybody can point me to the right road thanks. BTW i'm using codeigniter for my site.

example of what i am talking about is:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

**The Title**

sdfgsjdhfglksjhfdgksdjfhglskdjfghlsdkjfhglskdjfhgslkjdfhg(read more).

**The second title**   
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum(read more).
Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
tomexsans
  • 4,454
  • 4
  • 33
  • 49
  • 1
    You could look at this question http://stackoverflow.com/questions/965235/how-can-i-truncate-a-string-in-php – xdazz May 21 '12 at 03:04

2 Answers2

3

or you can use the built-in text helper http://s.zah.me/KJXK6o and use one of the two functions word_limiter or character_limiter

like

$string = "Here is a nice text string consisting of eleven words.";

$string = word_limiter($string, 4);

// Returns: Here is a nice…
Zaher
  • 1,120
  • 7
  • 18
  • Yes, silly of me not to read the user guide, Codeigniter comes with this helper.. thank you for pointing it out – tomexsans May 23 '12 at 04:09
2

There are a bunch of ways you can do this depending on where you want to cut it off.

An easy way is to split the string with a space then take the first X spaces/

$excerpt = array_slice( explode( " ", $text ), 0, 30 );

This way it wont cut the text off in the middle of a word.

Galen
  • 29,976
  • 9
  • 71
  • 89