What considerations should be taken into account when implementing text truncation in a PHP-based content management system?

When implementing text truncation in a PHP-based content management system, it is important to consider the length of the truncated text, whether to include an ellipsis (...) at the end, and how to handle HTML tags within the text.

function truncate_text($text, $length, $ellipsis = true) {
    $truncated_text = substr($text, 0, $length);
    if ($ellipsis && strlen($text) > $length) {
        $truncated_text .= '...';
    }
    return $truncated_text;
}

// Example usage
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
$truncated_text = truncate_text($text, 20);
echo $truncated_text;