What function in PHP can be used to wrap text at a certain character limit, such as 40 characters?

To wrap text at a certain character limit in PHP, you can use the wordwrap() function. This function takes a string, a character limit, and an optional parameter for a line break character, and returns the string with line breaks inserted at the specified character limit. This is useful for formatting text to fit within a certain width, such as in email messages or printed documents.

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