Last active
August 30, 2017 13:26
-
-
Save dryks/8c7b2760f784a624fc35a709cfd299be to your computer and use it in GitHub Desktop.
функция Обрезание по колличеству слов function php word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// функция Обрезание по колличеству слов | |
<? | |
function words_limit($input_text, $limit = 50, $end_str = '') { | |
$input_text = strip_tags($input_text); | |
$words = explode(' ', $input_text); // создаём из строки массив слов | |
if ($limit < 1 || sizeof($words) <= $limit) { // если лимит указан не верно или количество слов меньше лимита, то возвращаем исходную строку | |
return $input_text; | |
} | |
$words = array_slice($words, 0, $limit); // укорачиваем массив до нужной длины | |
$out = implode(' ', $words); | |
return $out.$end_str; //возвращаем строку + символ/строка завершения | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment