In what situations would using nl2br be appropriate for formatting shell command output in PHP?

When displaying shell command output in PHP, using the nl2br function can be appropriate to preserve line breaks and make the output more readable in a web context. This function converts newline characters (\n) to HTML line breaks (<br>) so that the output is displayed properly in an HTML document.

&lt;?php
$command_output = shell_exec(&#039;your_shell_command_here&#039;);
echo nl2br($command_output);
?&gt;