Skip to content

Instantly share code, notes, and snippets.

@zaurmag
Last active August 7, 2016 17:35
Show Gist options
  • Save zaurmag/e7338a63e83ef0ba6774177af5524613 to your computer and use it in GitHub Desktop.
Save zaurmag/e7338a63e83ef0ba6774177af5524613 to your computer and use it in GitHub Desktop.
Функция обрезания текста на php
<?php
$text = strip_tags($curr->name);
if (!function_exists('truncate_words')) {
function truncate_words($text, $limit=30) {
$text=mb_substr($text,0,$limit);
/*если не пустая обрезаем до последнего пробела*/
if(mb_substr($text,mb_strlen($text)-1,1) && mb_strlen($text)==$limit) {
$textret=mb_substr($text,0,mb_strlen($text)-mb_strlen(strrchr($text,' ')));
if(!empty($textret)) {
return $textret."...";
}
}
return $text;
}}
echo truncate_words($text);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment