Step 1:- Html code
<!DOCTYPE html>
<html>
<head>
<title>Replace Newlines Example</title>
</head>
<body>
<h1>Text with Newlines:</h1>
<pre>{{ $textWithNewlines }}</pre>
<h1>Text with Line Breaks:</h1>
<p>{!! $textWithLineBreaks !!}</p>
</body>
</html>
Step 2:- web.php
Route::get('/',[UserController::class,'View'])->name('view');
Step 3:- Controller
public function View()
{
$textWithNewlines = "This is line 1.\nThis is line 2.\nThis is line 3.";
$textWithLineBreaks = nl2br($textWithNewlines);
return view('importFile', compact('textWithLineBreaks','textWithNewlines'));
}
Output: