Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove HTML tags from Strings on laravel blade

I want remove HTML tags (all) from a string on laravel blade ...

code

{!! \Illuminate\Support\Str::words($subject->body, 5,'...')  !!} 

output (example)

<p>hassen zouari</p> 

I want that it be like this

hassen zouari 
like image 546
hassen zouari Avatar asked Mar 27 '16 12:03

hassen zouari


People also ask

How do I remove a specific HTML tag from a string in PHP?

You can always use strip_tags() with a second parameter containing the allowable tags. preg_replace('/<script>(. *)</script>/i', '$1', $input);

How do I remove all tags from a string?

To strip out all the HTML tags from a string there are lots of procedures in JavaScript. In order to strip out tags we can use replace() function and can also use . textContent property, . innerText property from HTML DOM.

Is it possible to remove the HTML tags from data?

Strip_tags() is a function that allows you to strip out all HTML and PHP tags from a given string (parameter one), however you can also use parameter two to specify a list of HTML tags you want.

How do I remove the HTML tag from a CSV file?

csv using open() function in 'read' mode. We further call readlines() to read the file content into a python list. Then we re-open the file in 'write' mode using open() function. We loop through the list items one by one and call cleanhtml() function on each line, to remove any HTML tags in it.


1 Answers

Try to use strip_tags() function:

http://php.net/manual/en/function.strip-tags.php

Update: Try to do something like this in a controller:

$taglessBody = strip_tags($subject->body); 

Then pass this variable into a blade template and use it instead of $subject->body.

like image 194
Alexey Mezenin Avatar answered Sep 19 '22 21:09

Alexey Mezenin