str::excerpt($string, $chars = 140, $removehtml = true, $rep = '…')

Creates an excerpt of a string It removes all html tags first and then uses str::short

  • $string (string)
    The string to be shortened
  • $chars (int)
    The final number of characters the string should have
  • $removehtml (boolean)
    True: remove the HTML tags from the string first
  • $rep (string)
    The element, which should be added if the string is too long. Ellipsis is the default.
  • return (string)
    The shortened string

Example

<?php
$string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. <em>Aenean</em> commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.';

$excerpt = str::excerpt($string, 80, false);
echo $excerpt;

$excerpt = str::excerpt($string, 80);
echo $excerpt;

Result:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. <em>Aenean</em>…

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula…