Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:51:25+00:00 2026-06-05T09:51:25+00:00

how to display only image in simplepie when using rss feed.I am using simplepie

  • 0

how to display only image in simplepie when using rss feed.I am using simplepie but enable to extract only image from rss.How to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:51:27+00:00Added an answer on June 5, 2026 at 9:51 am

    Considering certain feed structures are different, there is not an explicit way of doing this that I know of. This is how I was able to do it.First check out this article:

    How to Display Thumbnail from WordPress RSS feed using SimplePie?

    I was able to copy and paste the code and make some minor changes

    I was not using WordPress, but it helped give me an idea of what needed to be done.

    Insert this code after feed->init();

        //This function will get an image from the feed
    
    function returnImage ($text) {
        $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
        $pattern = "/<img[^>]+\>/i";
        preg_match($pattern, $text, $matches);
        $text = $matches[0];
        return $text;
    }
    
    
        //This function will filter out image url which we got from previous returnImage() function
    
        function scrapeImage($text) {
            $pattern = '/src=[\'"]?([^\'" >]+)[\'" >]/';
            preg_match($pattern, $text, $link);
            $link = $link[1];
            $link = urldecode($link);
            return $link;
    
        }
    

    Now you want to call the functions so it searches the description, or in my case the content, to find the img tag and structure the output correctly. This is what my code looked like:

    foreach ($feed->get_items(0 , 3) as $item):
        $feedDescription = $item->get_content();
        $image = returnImage($feedDescription);
        $image = scrapeImage($image);
        $image_url= $item->get_permalink();
        $description = $item->get_description();
    ?>
            <div class="item">
                <h4><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>
                <div class="image-box"><?php echo '<a href="' . $image_url . '"><img src="' . $image . '" /></a>'."\n";?></div>
                <p><?php echo $description ?></p>
                <p><a href="<?php echo $item->get_permalink(); ?>">Continue Reading</a></p>   
            </div>
    
        <?php endforeach; ?>
    

    It may take some buggin, but once you know where your img tag exists in the feed, you can get simplepie to parse the feed and the function will find the tag and format so it is html ready.

    To only pull one post, you can edit your loop:

    foreach ($feed->get_items(0 , 1) as $item): 
    

    The first number (0) is the starting point, 0 being the latest posts. The second number (1) is how many posts to pull. Since you only want one image, you want that number to be 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display only part of image using the GWT Image widget; for
Trying to display an image only for Android users, but I don't want to
The Javascript below has a default image, but I would like display text only
I'm using this method to display a table and its content from SQLite on
Below is my code snippet , I want to display only 10 records from
I am using a background image to display as a button. The button shows
I am using CSS for hover and it works, but the hover image allow
Suppose there is a frame with some image.I want to display only those parts
I am using this example to display images, stored in my File-Stream Enabled database
hai my images are gallery all image display in same view but i expect

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.