1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-25 03:43:33 +01:00

Helper functions

This commit is contained in:
FreeScout 2019-07-26 21:58:02 -07:00
parent cceb140eb1
commit 73657915a3

View File

@ -893,6 +893,9 @@ class Helper
*/
public static function htmlToText($text)
{
// Process blockquotes.
$text = str_ireplace('<blockquote>', '<div>', $text);
$text = str_ireplace('</blockquote>', '</div>', $text);
return (new \Html2Text\Html2Text($text))->getText();
}
@ -1024,4 +1027,37 @@ class Helper
\Cache::forever('illuminate:queue:restart', Carbon::now()->getTimestamp());
}
/**
* UTF-8 split text into parts with max. length.
*/
public static function strSplitKeepWords($str, $max_length = 75)
{
$array_words = explode(' ', $str);
$currentLength = 0;
$index = 0;
$array_output = [''];
foreach ($array_words as $word) {
// +1 because the word will receive back the space in the end that it loses in explode()
$wordLength = strlen($word) + 1;
if (($currentLength + $wordLength) <= $max_length) {
$array_output[$index] .= $word . ' ';
$currentLength += $wordLength;
} else {
$index += 1;
$currentLength = $wordLength;
$array_output[$index] = $word;
}
}
return $array_output;
}
}