Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TruncateTextW(string $text, int $length) : string
- {
- $result = '';
- if (strlen($text) <= $length)
- {
- $result = $text;
- }
- else
- {
- $result = substr($text, 0, $length);
- $end = substr($text, $length);
- $m = null;
- if (preg_match('/([.,\s!?\r:;])/', $end, $m))
- {
- $firstSeparator = strpos($end, $m[1]);
- $result .= substr($end, 0, $firstSeparator).'...';
- }
- }
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement