Method to cut text with specified limit value and type (characters/words)

// Method to cut text with specified limit value and type (characters/words) function cutText($text, $limit_value, $limit_type) { if($limit_type == 'words' && $limit_value > 0) { $temp = explode(' ',$text); if(count($temp) > $limit_value) { for($i=0; $i<$limit_value; $i++) $cutted[$i] = $temp[$i]; $cutted = implode(' ', $cutted); $text = $cutted.$at_end; } } elseif ($limit_type == 'characters' && $limit_value > 0) { if(strlen($text) > $limit_value){ $text = substr($text, 0, $limit_value); } } return $text; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.