2016-03-27 22 views
9

voglio rimuovere i tag HTML (tutti) da una stringa sulla lama laravel ...rimuovere i tag HTML da stringhe sulla lama laravel

codice

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

uscita (esempio)

<p>hassen zouari</p> 

Voglio che sia così

hassen zouari 
+0

è possibile utilizzare strip_tags ($ stringa) per mettere a nudo i tag HTML. –

risposta

18

Prova ad utilizzare strip_tags() funzione:

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

Aggiornamento: provare a fare qualcosa di simile in un controllore:

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

quindi passare questa variabile in un modello di lama e usarlo al posto di $subject->body.

+0

grazie :) ma quando aggiungo {!! \ Illuminate \ Support \ Str :: words ($ subject-> body, 5, '...') !!} come stringa che voglio ahnge per questa funzione mostra un errore .. –

+0

l'aggiornamento funziona :) –

8

È possibile utilizzare strip_tags ($ yourString); per rimuovere i tag html. In lama si potrebbe raggiungere questo obiettivo

{{ strip_tags($yourString) }} 
//if your string is <h1> my string </h1> 
//output will be my string. 

speranza che è utile :)

+0

grazie :) ma quando aggiungo {!! \ Illuminate \ Support \ Str :: words ($ subject-> body, 5, '...') !!} come stringa che voglio ahnge per questa funzione mostra un errore .. –

+0

puoi postare l'errore stanno ottenendo? –

+0

"Somthing goes wrong ....." –

2

aggiungere il codice riportato di seguito in vostri aiutanti

if (! function_exists('words')) { 
     /** 
     * Limit the number of words in a string. 
     * 
     * @param string $value 
     * @param int  $words 
     * @param string $end 
     * @return string 
     */ 
     function words($value, $words = 100, $end = '...') 
     { 
      return \Illuminate\Support\Str::words($value, $words, $end); 
     } 
    } 

& uso questo nella vostra lama

{{ words($sentence), $limit = 20, $end = ' ..... more') }}

2

Per quanto mi riguarda, io uso questo contro truction:

{!! str_limit(strip_tags($post->text), $limit = 50, $end = '...') !!} 

spero, il mio codice è stato utile per qualcuno)

0

È possibile utilizzare

{{ strip_tags($value->description) }}