How to Remove HTML Tags from String in Laravel?

By Hardik Savani April 16, 2024 Category : Laravel

Hello Friends,

Here, I will show you how to work laravel remove html tags from string. you can understand a concept of how to remove html tags in laravel. It's a simple example of how to remove html tags from string in laravel. I’m going to show you about remove html tags from string in laravel controller. you will do the following things for laravel remove html tags from string example.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

If you want to remove all HTML tags from the string then we can use strip_tags() function of php. i will give you a simple example code with output for how to remove HTML tags from strings in laravel application. so let's see the bellow code of the controller file and blade file:

app/Http/Controllers/DemoController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

$tagsString = "Google <h1>Nice</h1>, Nice to <p>meet</p> you.";

return view("demo", compact("tagsString"));

}

}

views/demo.blade.php

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title></title>

</head>

<body>

<h1>How to Remove HTML Tags from String in Laravel? - ItSolutionStuff.com</h1>

{{ strip_tags($tagsString) }}

</body>

</html>

Output:

I hope it can help you...

Tags :
Shares