1.Ограничение на количество выводимых слов:
function getPrewText($text,$maxwords=60,$maxchar=50) {
//$text=strip_tags($text);
$words=split(' ',$text);
$text='';
foreach ($words as $word) {
if (mb_strlen($text.' '.$word)<$maxchar) {
$text.=' '.$word;
}
else {
$text.='...';
break;
}
}
return $text;
}
function kd_get_substr($count=20, $str='', $is_point = true){
$str_arr = explode(" ",$str);
if(count($str_arr)>=$count){
$out = '';
for($i=0;$i<$count;$i++){
$out .= $str_arr[$i].' ';
}
if($is_point == true){
return trim($out).' ...';
}else{
return trim($out);
}
}else{
return $str;
}
}
function limit_words($string, $word_limit) {
$words=explode(" ",$string);
return implode(" ",array_splice($words,0,$word_limit));
}