Skip to content

Commit

Permalink
Add wrapPlainText
Browse files Browse the repository at this point in the history
  • Loading branch information
dfridrich authored Apr 20, 2018
1 parent 0419901 commit 24a8b3f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1237,5 +1237,29 @@ public static function parseStringForSearch($string)
}

return $conditions;
}

/**
* @param string $input
* @param int $rowLength
* @return string
*/
public static function wrapPlainText($input, $rowLength = 50)
{
$words = explode(' ', $input);
$rows = [];
$row = '';

foreach ($words as $word) {
if (strlen($row . ' ' . $word) > $rowLength) {
$rows[] = trim($row);
$row = '';
}
$row .= ' ' . $word;
}
$rows[] = trim($row);

return implode("\n", $rows);
}

}

0 comments on commit 24a8b3f

Please sign in to comment.