CodeIgniter Forums
Display Excerpt - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Display Excerpt (/showthread.php?tid=37285)



Display Excerpt - El Forum - 01-04-2011

[eluser]HSKrustofsky[/eluser]
I was wondering if there was a way to display an excerpt of a blog topic and/or video description? I saw in the user guide that you could use the Trackback Class. I noticed that it said that the lowest it goes is 500 characters. Is there was something to where less was shown?


Display Excerpt - El Forum - 01-04-2011

[eluser]Medikal[/eluser]
I used a custom function on mine to be honest:
Code:
function excerptString($string, $desLength, $endChars = '...', $before = '1', $offChar = ' ')
{
    if (strlen($string) < $desLength)
    {
        return $string;
    }

switch($before)
{
case 0:
$partialString = substr($string, $desLength, strlen($string));
$endPosition = strpos($partialString, $offChar);
return substr($string, 0, $desLength+$endPosition).$endChars;
break;

case 1:
$string = substr($string, 0, $desLength);
$endPosition = strrpos($string, $offChar);
return $string = substr($string, 0, $endPosition).$endChars;
break;

}

}

Further explanation of how to use it is here:
http://danlamanna.com/portfolio/?p=24


Display Excerpt - El Forum - 01-05-2011

[eluser]InsiteFX[/eluser]
See the CodeIgniter Typography Class.

Also see this:

CodeIgniter User Guide - Text Helper

InsiteFX