How should the wordwrap function be correctly implemented in PHP scripts?

When displaying text on a webpage, it is important to ensure that long lines of text do not break the layout. The wordwrap function in PHP can be used to break long lines of text into smaller lines by inserting line breaks at specified intervals. This function takes the input text, the number of characters per line, and an optional parameter to specify the line break character.

$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
$wrapped_text = wordwrap($text, 30, "<br>");
echo $wrapped_text;