What is the difference between using eregi_replace() and nl2br() functions to handle line breaks in PHP?

When handling line breaks in PHP, the eregi_replace() function is used to replace a specified pattern with another in a string, while the nl2br() function is specifically designed to convert newline characters (\n) into HTML line breaks (<br>). If you need to simply convert newline characters to HTML line breaks, nl2br() is the appropriate function to use. On the other hand, if you need to replace specific patterns in a string, eregi_replace() would be more suitable.

// Using nl2br() to convert newline characters to HTML line breaks
$text = &quot;Hello\nWorld!&quot;;
echo nl2br($text);