What are some best practices for handling word wrapping in PHP output to prevent layout issues?

When outputting text in PHP, it's important to handle word wrapping to prevent layout issues such as text overflowing its container or breaking unevenly. One way to handle word wrapping is by using the PHP function `wordwrap()` which breaks long lines of text into multiple lines with a specified line length. By specifying a maximum line length, you can ensure that text is wrapped appropriately within the layout.

<?php
$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, "\n");
echo $wrapped_text;
?>