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 128901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:42:31+00:00 2026-05-11T05:42:31+00:00

I use Simple HTML DOM to scrape a page for the latest news, and

  • 0

I use Simple HTML DOM to scrape a page for the latest news, and then generate an RSS feed using this PHP class.

This what I have now:

<?php   // This is a minimum example of using the class  include('FeedWriter.php');  include('simple_html_dom.php');   $html = file_get_html('http://www.website.com');  foreach($html->find('td[width='380'] p table') as $article) { $item['title'] = $article->find('span.title', 0)->innertext; $item['description'] = $article->find('.ingress', 0)->innertext; $item['link'] = $article->find('.lesMer', 0)->href;      $item['pubDate'] = $article->find('span.presseDato', 0)->plaintext;      $articles[] = $item; }   //Creating an instance of FeedWriter class.  $TestFeed = new FeedWriter(RSS2);    //Use wrapper functions for common channel elements   $TestFeed->setTitle('Testing & Checking the RSS writer class');  $TestFeed->setLink('http://www.ajaxray.com/projects/rss');  $TestFeed->setDescription('This is test of creating a RSS 2.0 feed Universal Feed Writer');    //Image title and link must match with the 'title' and 'link' channel elements for valid RSS 2.0    $TestFeed->setImage('Testing the RSS writer class','http://www.ajaxray.com/projects/rss','http://www.rightbrainsolution.com/images/logo.gif');   foreach($articles as $row) {      //Create an empty FeedItem     $newItem = $TestFeed->createNewItem();      //Add elements to the feed item         $newItem->setTitle($row['title']);     $newItem->setLink($row['link']);     $newItem->setDate($row['pubDate']);     $newItem->setDescription($row['description']);      //Now add the feed item     $TestFeed->addItem($newItem); }    //OK. Everything is done. Now genarate the feed.   $TestFeed->genarateFeed();  ?> 

How can I make this code simpler? Right know there is two foreach statements, how can I combine them?

Because the news scraped is in Norwegian, I need to apply the html_entity_decode() on the title. I’ve tried It here, but I couldn’t get it to work:

foreach($html->find('td[width='380'] p table') as $article) { $item['title'] = html_entity_decode($article->find('span.title', 0)->innertext, ENT_NOQUOTES, 'UTF-8'); $item['description'] = '<img src='' . $article->find('img[width='100']', 0)->src . ''><p>' . $article->find('.ingress', 0)->innertext . '</p>';     $item['link'] = $article->find('.lesMer', 0)->href;      $item['pubDate'] = unix2rssdate(strtotime($article->find('span.presseDato', 0)->plaintext)); $articles[] = $item; }  

Thanks 🙂

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:42:31+00:00Added an answer on May 11, 2026 at 5:42 am

    Well for just a simple combination of the two loops you could create the feed as your parse through the HTML:

    <?php include('FeedWriter.php'); include('simple_html_dom.php');  $html = file_get_html('http://www.website.com');  //Creating an instance of FeedWriter class.  $TestFeed = new FeedWriter(RSS2); $TestFeed->setTitle('Testing & Checking the RSS writer class'); $TestFeed->setLink('http://www.ajaxray.com/projects/rss'); $TestFeed->setDescription(   'This is test of creating a RSS 2.0 feed Universal Feed Writer');  $TestFeed->setImage('Testing the RSS writer class',                     'http://www.ajaxray.com/projects/rss',                     'http://www.rightbrainsolution.com/images/logo.gif');  //parse through the HTML and build up the RSS feed as we go along foreach($html->find('td[width='380'] p table') as $article) {   //Create an empty FeedItem   $newItem = $TestFeed->createNewItem();    //Look up and add elements to the feed item      $newItem->setTitle($article->find('span.title', 0)->innertext);   $newItem->setDescription($article->find('.ingress', 0)->innertext);   $newItem->setLink($article->find('.lesMer', 0)->href);        $newItem->setDate($article->find('span.presseDato', 0)->plaintext);         //Now add the feed item   $TestFeed->addItem($newItem); }  $TestFeed->genarateFeed(); ?> 

    What’s the issue you’re seeing with html_entity_decode, if you give us a link to a page it doesn’t work on that might help?

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

Sidebar

Related Questions

I'm editing web pages directly using ajax, and php with simple html dom. I
I want to use the PHP Simple HTML DOM Parser to display all my
I'm using PHP simple dom parser http://simplehtmldom.sourceforge.net/manual.htm . I'm able to successfully use it
I wanted to use PHP Simple HTML DOM Parser to grab the Google Apps
I just started to use PHP Simple HTML DOM Parser . Now I'm trying
I am using PHP Simple HTML DOM to parse a webpage. Problem: However, the
I'm using Simple HTML DOM to scrape (with permission) some websites. I basically scrape
I want to use the php simple HTML DOM parser to grab the image,
I have use Simple DOM Parser in PHP but since I am using jQuery
I'm using simple html DOM and extracting two links from website. function get_links($website) {

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.