0

I am trying to implement a preview for various articles, the preview should be a small part of the full article to give the reader and idea of the content.

My current solution is to load all content as text and display it in a div with a max-width of 300px and overflow hidden. While this does work it does not seem like the best solution.

I though that maybe selecting a part of the content using mysql would be an option. How would I approach getting a preview, should I just get N characters or does MYSQL have more tailored functions for this behaviour.

MaartenDev
  • 5,631
  • 5
  • 21
  • 33
jalal mobini
  • 95
  • 1
  • 6

1 Answers1

1

You can use Text Helper that come up with codeigniter. There are 2 functions that can use to achieve your desired result. I prefer character_limiter().

  • character_limiter() Truncates a string to the number of characters specified. It maintains the integrity of words
$string = "Here is a nice text string consisting of eleven words.";
$string = character_limiter($string, 20);
// Returns:  Here is a nice text string
  • word_limiter() Truncates a string to the number of words specified
$string = "Here is a nice text string consisting of eleven words.";
$string = word_limiter($string, 4);
// Returns:  Here is a nice
Dum
  • 1,431
  • 2
  • 9
  • 23