Self explanatory function to get limited text from long paragraph.

function limit_text($mystring, $no_of_chars, $append_text)
//Varaible definition
//$mystring -> Text string that need to be process
//$no_of_chars -> Number of character to be display
//$append_text -> Append text at the end of truncated text to show more to read.
//like “Continue..”,”….”, “[..]”

$no_of_chars = strpos($mystring,” “,$no_of_chars);
// Seeking position of space after allowed character length to prevent word from cut down.
$rstring = substr($mystring,0,$no_of_chars).$append_text;
// retrieve sub string till allowed character and add append text
return $rstring;
//return string..

Written by Bala Krishna

Bala Krishna is web developer and occasional blogger from Bhopal, MP, India. He like to share idea, issue he face while working with the code.

This article has 4 comments