Search code examples
phplaravelrss

How to display image from an RSS Feed description using PHP Laravel


Im working in PHP Laravel to build an RSS FEED READER

I have read the XML file and it displays the title, description and link. But the description contains image which i don't know how to display as an image. Now the image part comes in html format as shown below:

enter image description here

Instead i want it to be displayed like this:

enter image description here

Here is my html code where the rss feed content display happens:

 @foreach ($feed->item as $item)
        <tbody>
          <div class="card">
            <div class="card-header">
              <a href="{{ $item->link }}">{{ $item->title}}</a>
            </div>

            <div class="card-header">
              <a href="{{ $item->link }}">{{ $item->thumbnail}}</a>
            </div>
            <div class="card-body">
              {{$item->description}}
            </div>
          </div>
        </tbody>
        @endforeach

Can somebody please help me with this. Thanks in advance.


Solution

  • You have HTML in your $item->description using the double Mustache{{ }} You are telling Laravel escape the data.

    To render the HTML, you need to use instead {!! !!}

        <div class="card-body">
          {!! $item->description !!}
        </div>
    

    You can see more in the doc here: https://laravel.com/docs/7.x/blade#displaying-data