function truncateStr strText intLen endStr type text switch type case

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function truncateStr($strText, $intLen, $endStr = "", $type = "text")
{
switch($type)
{
case "html":
$obParser = new CTextParser;
$symbols = strip_tags($strText);
$symbols_len = strlen($symbols);
if($symbols_len < strlen($strText))
{
$strip_text = $obParser->strip_words($strText, $intLen);
if($symbols_len > $size)
$strip_text = $strip_text.$endStr;
$final_text = $obParser->closetags($strip_text);
}
elseif($symbols_len > $strText)
$final_text = substr($strText, 0, $intLen).$endStr;
else
$final_text = $html;
return $final_text;
break;
case "text":
if(strlen($strText) > $intLen)
return rtrim(substr($strText, 0, $intLen), ".").$endStr;
else
return $strText;
break;
}
}