Can SimplePie grab images from feeds

前端 未结 2 1362
长情又很酷
长情又很酷 2020-12-17 07:26

I am using this simplepie and i have uploaded the files to my host. Everything seems to be working fine except one thing. The blog that i\'m getting the feed from has images

相关标签:
2条回答
  • 2020-12-17 07:46

    Yes, you can call get_content() and the entire post or the portion of the post that is included in the feed will be outputted to the screen, all the HTML tags included. If you want to pull say the first image in the post, you have to do a little more work, here is what I've been doing.

    $htmlDOM = new simple_html_dom();
    $htmlDOM->load($item->get_content());
    $image = $htmlDOM->find('img', 0); 
    $html .= '<img src="thumbnail.php?file=' . $image->src . '&maxw=300&maxh=300" border="0" />';
    

    That snippet from my current little project, uses simple_html_dom and another script I got off the Internet to resize images on the fly. If you just want to display the image not resize it at all $image->src is the URL. I think functionality like this may be added to SimplePie in the future or an add-on to SimplePie, but in the mean time, it is four lines of code to display the first image from an item from a feed.

    0 讨论(0)
  • This tutorial will help you to embed images in simple pie output.

    0 讨论(0)
提交回复
热议问题