1function preview($text)
2// we don't want new lines in our preview
3$text_only_spaces = preg_replace('/\s+/', ' ', $text);
4// truncates the text
5$text_truncated = mb_substr($text_only_spaces, 0, mb_strpos($text_only_spaces, " ", 50));
6// prevents last word truncation
7$preview = trim(mb_substr($text_truncated, 0, mb_strrpos($text_truncated, " ")));
8$preview."...";
9}