hi all

i want to display news from other website and display them to my site using php & mysql.how to achive step wise???

Dani AI

Generated

A concise, practical plan for pulling news into a PHP + MySQL site, expanding on 's pointer to use feeds/APIs and tailoring it for someone starting from scratch ().

  • Discover sources: prefer an official feed or public API (RSS/Atom/JSON). If none exists, a scraper may work but check robots.txt and the site's Terms of Service first.
  • Fetch and parse: use a server-side HTTP client (cURL) to fetch, then parse with SimpleXML or DOM for XML feeds, or decode JSON for APIs. Set a reasonable User-Agent and follow redirects.
  • Store and dedupe: keep a feeds table and an items table. Use the feed GUID (or a hash of the link+title) as a unique key to avoid duplicates. Store title, link, content, pubDate, fetched_at, and feed_id.
  • Schedule and cache: don’t fetch on every page load. Use cron (or a background worker) to poll sources and cache results in the DB. Respect ETag/If-Modified-Since when available to reduce bandwidth.
  • Sanitize and display: sanitize HTML before rendering (strip scripts, use an HTML sanitizer) and always escape output to prevent XSS. Show original source attribution and links.

Example skeleton (fetch + parse + insert):

$xml = simplexml_load_string(fetch($feedUrl)); // fetch() uses cURL
foreach ($xml->channel->item as $it) {
  $guid = (string)($it->guid ?: md5((string)$it->link));
  // check DB for guid; if missing, insert with prepared statement (PDO)
}

Quick DB layout:

CREATE TABLE feeds (id INT AUTO_INCREMENT PRIMARY KEY, url VARCHAR(255));
CREATE TABLE items (id INT AUTO_INCREMENT PRIMARY KEY, feed_id INT, guid VARCHAR(255) UNIQUE, title VARCHAR(255), link VARCHAR(2083), content TEXT, pubDate DATETIME, fetched_at DATETIME);

Notes: use prepared statements (PDO/mysqli), rate-limit requests, and respect copyright/attribution rules. If multiple feeds are needed, consider a mature feed library (eg. SimplePie) to save parsing edge cases.

Recommended Answers

All 2 Replies

It's called Aggregator. You can google "RSS Aggregator" or "PHP Aggregator"

It's called Aggregator. You can google "RSS Aggregator" or "PHP Aggregator"

hey dude ,

i have not much idea about php Aggregator.any other way to do this??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.