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:


I’m Abhishek, a DevOps, SRE, DevSecOps, and Cloud expert with a passion for sharing knowledge and real-world experiences. I’ve had the opportunity to work with Cotocus and continue to contribute to multiple platforms where I share insights across different domains:
-
DevOps School – Tech blogs and tutorials
-
Holiday Landmark – Travel stories and guides
-
Stocks Mantra – Stock market strategies and tips
-
My Medic Plus – Health and fitness guidance
-
TrueReviewNow – Honest product reviews
-
Wizbrand – SEO and digital tools for businesses
I’m also exploring the fascinating world of Quantum Computing.