Jump to content
php.lv forumi

Ka var izveidot savu RSS?


foxc

Recommended Posts

Aptuveni šādi:

<?php

header("Content-type: application/rss+xml");

$site_domain = "some.lv";
$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><rss version="2.0"></rss>');

$channel = $xml->addChild('channel');
$channel->addChild('title', ent('Some title'));
$channel->addChild('link', ent("http://$site_domain/"));
$channel->addChild('description', ent('Some description'));

$image = $channel->addChild('image');
$image->addChild('url', ent("http://$site_domain/img/some-logo.png"));
$image->addChild('link', ent("http://$site_domain/"));

foreach($items as $id=>$item)
{
$xmlItem = $channel->addChild('item');
$xmlItem->addChild("title", ent($item['virsraksts']));
$xmlItem->addChild("link", "http://$site_domain/news.html?id=$id");
$xmlItem->addChild("description", ent($item['content']));
}

print $xml->asXML();

function ent($data)
{
return htmlspecialchars($data, ENT_COMPAT, 'utf-8');
} // ent

Link to comment
Share on other sites

Tas nozīmē meklē kļūdu. Pārbaudi kas darbojas un kas nē. Kad atradīsi vietu, kas nedarbojas, tad pārbaudi kāpēc - mainīgo vērtības, koda loģiku un tml. Tad kad sapratīsi kāpēc - tad izlabo kļūdu un viss darbosies.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...