Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

Replace \n with br in Laravel

Laravel

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:

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x