Simple function to get subset of words from a big string. Use this simple function to trim a big sentence into a short string with subset of words.
function getTrimedSentence($string, $max_length, $offset=0, $add_dots=1){
$words_array = explode(" ", $string);
return
($add_dots && $offset>0 ? " ... " : "") .
implode(" ", array_splice($words_array, $offset, $max_length)) .
($add_dots && $max_length < count($words_array) ? " ... " : "");
}
function getTrimedSentence($string, $max_length, $offset=0, $add_dots=1){
$words_array = explode(" ", $string);
return
($add_dots && $offset>0 ? " ... " : "") .
implode(" ", array_splice($words_array, $offset, $max_length)) .
($add_dots && $max_length < count($words_array) ? " ... " : "");
}
No comments:
Post a Comment