How to remove HTML Tags from strings using Laravel?
In this tutorial How to remove HTML Tags from strings using Laravel? you can understand the concept of how to remove HTML tags from strings in Laravel. a simple way to create an example of how to remove HTML tags from strings in Laravel. I will show you how to work with Laravel to remove HTML tags from strings. I will show you about removing HTML tags from strings in the Laravel controller. I want to remove all HTML tags from the strings. So we can use strip_tags()
the function of PHP.
I will give you a simple example of How to remove HTML Tags from strings using Laravel? code with output. You can easily use this example with Laravel 6, Laravel 7, Laravel 8, and Laravel 9 versions.
app/Http/Controllers/HomeController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller {
public function index(Request $request) {
$strings = "How to <p>remove HTML</p> Tags from strings using <h2>Laravel</h2>?";
return view("index", compact("strings"));
}
}
views/index.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to remove HTML Tags from strings using Laravel?</title>
</head>
<body>
<h1>How to remove HTML Tags from strings using Laravel?</h1>
{{ strip_tags($strings) }}
</body>
</html>
routes/web.php
Route::get('home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');