method cut documentation in bbn\Str
Cuts a string (HTML and PHP tags stripped) to maximum length inserted.
Example
X::dump(\bbn\Str::cut(" Example text", 7));
// (string) "Example..."
function(string $st, int $max = 15)
{
$st = self::cast($st);
$st = self::html2text($st);
$st = mb_ereg_replace('\n', ' ', $st);
$st = self::cleanSpaces($st);
if (mb_strlen($st) >= $max) {
// Chars forbidden to finish with a string
$chars = [' ', '.'];
// The string gets cut at $max
$st = mb_substr($st, 0, $max);
while (\in_array(substr($st, -1), $chars)){
$st = substr($st, 0, -1);
}
$st .= '...';
}
return $st;
}
Cuts a string (HTML and PHP tags stripped) to maximum length inserted. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions