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 Hemant Patel

Hemant, hailing from Bhopal, Madhya Pradesh, India, is a web developer and occasional blogger passionate about exchanging ideas and addressing problems in his coding journey.

This article has 4 comments