欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

移除标签

$taglessBody = strip_tags($subject->body);
{{ strip_tags($yourString) }} 


{!!  !!}

Stripping tags when viewing

I use CKEditor for adding content(instead of Textarea box).

When I display the content, it shows Tags, images,.. so I stripped by using

'e' method(and also using {{{ }}} )

However when I display the text, it shows

<p> Testing </p> <img src="/assets/img/1.jpg" > 

How to safely sanitise the output to html ?

sivaganeshsg
sivaganeshsg
  • 3 years ago

Try it with two of the {{'s.

For example:

Sanitized: {{{ $var }}}

Not sanitzied: {{ $var }}

escaping is making sure the content doesn't get executed, so instead of an image, you see `<img ..> in plain text. That is safe. But if you want to remove all html, you can use http://php.net/strip_tags

@barryvdh: thanks :)

hi

http://laravel.io/bin/32r7

I used such code to display content (using cketditor) But it display content with html tags. Can u help me.

I tried with {{{$page->description}}} but no help

Here I solved it with some help from uncle Google and some good guys like us that like to share their knowledge.

{{ preg_replace('/(<.*?>)|(&.*?;)/', '', $string) }}

the

(<.*?>) 

seems to strip all the html tags pretty well.

(&.*?;) 

strips all the HTML special characters, like:

© <, > 

and other stuff

Try

strip_tags($string)

It will give you just plain text form string. It helped of me.

来自 https://laravel.io/forum/02-12-2014-stripping-tags-when-viewing?page=1
普通分类: