Last active
August 7, 2016 17:35
-
-
Save zaurmag/e7338a63e83ef0ba6774177af5524613 to your computer and use it in GitHub Desktop.
Функция обрезания текста на php
This file contains hidden or 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
<?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