Skip to content

Commit

Permalink
Truncator Update
Browse files Browse the repository at this point in the history
* Now returns the Complete Word at the end of the truncated text.
* If the length is less than the specified length, text is not sent to truncation.
* read more... has been changed to ...see more
* Now supports the UTF-8 Chars.
  • Loading branch information
RodWizard committed Aug 31, 2017
1 parent 21e29fa commit c09daa5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Trickster.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ public function __construct()
* @param string $suffix What do you want to show at the end
* @return mixed Return truncated text with suffix
*/
public function truncator($text, $number, $suffix = ' read more...')
public function truncator($text, $number, $suffix = ' ...see more')
{
if (!empty($text) && intval($number)) {
return substr($text, 0, $number) . $suffix;
if(strlen($text) > $number) {
return mb_substr($text, 0, mb_strpos($text, ' ', $number, 'UTF-8'), 'UTF-8') . $suffix;
}
return $text;
}
return false;
}
Expand Down

0 comments on commit c09daa5

Please # to comment.