Best Cosmetic Hospitals Near You

Compare top cosmetic hospitals, aesthetic clinics & beauty treatments by city.

Trusted • Verified • Best-in-Class Care

Explore Best Hospitals

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:

Best Cardiac Hospitals Near You

Discover top heart hospitals, cardiology centers & cardiac care services by city.

Advanced Heart Care • Trusted Hospitals • Expert Teams

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