What are the potential challenges when trying to display a fixed number of lines from a text without manual line breaks in PHP?

When trying to display a fixed number of lines from a text without manual line breaks in PHP, one potential challenge is determining the appropriate line length to ensure the text is displayed correctly. Another challenge is handling cases where words are cut off at the end of a line. One solution is to use the wordwrap() function in PHP to automatically insert line breaks at the specified length.

$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

$lines = explode("\n", wordwrap($text, 30, "\n"));

for ($i = 0; $i < 3; $i++) {
    echo $lines[$i] . "<br>";
}