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

  • SEARCH
  • Home
  • 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 8968845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:30:36+00:00 2026-06-15T17:30:36+00:00

Here you have my code: <?php $url = http://feeds.hipertextual.com/alt1040; $rss = simplexml_load_file($url); if($rss) {

  • 0

Here you have my code:

<?php
$url = "http://feeds.hipertextual.com/alt1040";
$rss = simplexml_load_file($url);
if($rss) {
$items = $rss->channel->item;

    foreach($items as $item) {
        $title = $item -> title;
        $link = $item -> link;
        $description = $item -> description;
        $replace = preg_replace("/<img[^>]+\>/i", "", $description);
        echo utf8_decode("<h3><a href=$link>$title</a></h3>");
        echo utf8_decode("<p>$replace</p>");

    }
}
?>

I get the RSS from that URL and I parse it so that images don’t appear. Until here OK.
But now, I want only to be shown the first piece of news from the RSS Feed, not all the news.

If I make a count, it tells there are 25 news items.

$count = count ($items);
echo $count; //25 news...

How can I do to be only shown the first piece of news?

  • 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-15T17:30:37+00:00Added an answer on June 15, 2026 at 5:30 pm

    You can insert any number instead of 1 item in this example.

     <?php
        $url = "http://feeds.hipertextual.com/alt1040";
        $rss = simplexml_load_file($url);
        if($rss) {
        $items = $rss->channel->item;
        $count =0;
            foreach($items as $item) {
                if ($count<1) {
                $title = $item -> title;
                $link = $item -> link;
                $description = $item -> description;
                $replace = preg_replace("/<img[^>]+\>/i", "", $description);
                echo utf8_decode("<h3><a href=$link>$title</a></h3>");
                echo utf8_decode("<p>$replace</p>");
                }
                $count++;
            }
        }
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found some code on measuring execution time here http://www.dreamincode.net/forums/index.php?showtopic=24685 However, it does
This is my code, $.ajax({ type:get, //this doesn't work //url:'http://example.com/json.php', //But this works url:'http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?',
I have a class called myClass in /myDir/myClass.php. When user types url: http://mysite.com/myDir/myClass.php, I
So I have some PHP code that looks like: $message = 'Here is the
here is my mysql and php code layout: I have 3 tables tableA stores
i have this code right here: <select name=group> <option value=>Choose a group....</option> <?php foreach($groups
I am modifying my PHP network's code to have user roles like wordpress here
Here my code, I need to insert into mysql database I have mysql,php,android 1)
Sigh, regex trouble again. I have following in $text : [img]http://www.site.com/logo.jpg[/img] and [url]http://www.site.com[/url] I
Here I have piece of code, showing example of how I want to update

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.