Search code examples
phplaravelrsssimplepie

simplePie: substring description without removing the images for every news


hello im trying to limit the text of every single news , my code works fine like this

<p> {{ substr(strip_tags($item->get_description()), 0, 500) }} </p>

but one thing i noticed, it removes all of the images of the news. is there any tricks to avoid that? thank you in advance


Solution

  • The second argument to strip_tags lets you specify tags not to strip out. So, you can specify not to string out <img> tags. You'll also need to change your blade output tags to {!! !!} so that the html won't get escaped (assuming you're on Laravel 5).

    <p> {!! substr(strip_tags($item->get_description(), '<img>'), 0, 500) !!} </p>