How to change php code to display image
-
Hi, This seems promising. I currently have an internal app that was displaying a feed from my blog – showing just the title and description text. Installed the plugin and can confirm that the rss feed is showing the image (blog.dealforma.com/feed). However, now what’s showing in the app is just showing the code from the feed rather than the image. Any ideas on how to parse it?
This is what shows in the app:
The Marketplace Concept
<img width=”150″ height=”150″ src=”https://blog.dealforma.com/wp-content/uploads/2017/10/Pills3-150×150.jpg” class=”webfeedsFeaturedVisual wp-post-image” alt=”” style=”display: b…Code for the display end (followed by the php code pulling it)
<div class=”media”>
@foreach($blog as $post)
<div class=”media-body”>
<h4 class=”media-heading”>{{ $post[‘title’] }}</h4>
{{ $post[‘description’] }}
</div>
<div class=”col-xs-12 mt-0 mb-1″>
<span class=”float-xs-right”>Continue reading at blog.dealforma.com</span>
</div>
@endforeach
</div>and in the controller pulling it:
$blog = [];
$client = new GuzzleHttp\Client([‘verify’ => false]);
$res = $client->get(‘https://blog.dealforma.com/feed/’);
$body = $res->getBody();
$data = new SimpleXMLElement($body);foreach ($data->channel->item as $item) {
$post = [];
$post[‘title’] = (string)$item->title;
$post[‘description’] = (string)$item->description;
$post[‘pubDate’] = strtotime((string)$item->pubDate);
if (strlen($post[‘description’]) > 180) {
$post[‘description’] = substr($post[‘description’], 0, 178) . ‘…’;
}
$post[‘link’] = (string)$item->link;
$blog[] = $post;
}
usort($blog, function ($a, $b) {
return $b[‘pubDate’] <=> $a[‘pubDate’];
});
$blogSlice = [];
if (count($blog) >= 5) {
$blogSlice = array_slice($blog, 0, 5, true);
} else {
$blogSlice = $blog;
}
return view(‘user.index.user-home’)->with([‘people’ => $people, ‘companies’ => $companies,
‘products’ => $products, ‘deals’ => $deals, ‘fundings’ => $fundings, ‘savedSearches’ => $savedSearches,
‘blog’ => $blogSlice]);
The topic ‘How to change php code to display image’ is closed to new replies.