The nl2br function inserts HTML line breaks before all newlines in a string.

    
    $string = "Hello\nWorld!";
    $stringNl2Br = nl2br($string);

    echo $stringNl2Br;
    // Hello
World!