What potential issues can arise when limiting text length in PHP for display purposes?

Limiting text length in PHP for display purposes can lead to truncated text that may affect the readability or context of the content. To solve this issue, you can add an ellipsis (...) at the end of the truncated text to indicate that there is more content available.

function limit_text($text, $limit) {
    if (strlen($text) > $limit) {
        $text = substr($text, 0, $limit);
        $text = substr($text, 0, strrpos($text, ' ')) . '...';
    }
    return $text;
}

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