PDA

View Full Version : سوال: چطور عکسهای توی rss رو بخونیم؟



p30graph3
پنج شنبه 15 بهمن 1388, 17:51 عصر
سلام

من یک چیزی ساختم برای خوندن آر اس اس

چطور میشه با پی اچ پی عکس های توی یک مورد مثلا مطلب رو هم بخونیم؟

Lagon666
پنج شنبه 15 بهمن 1388, 18:26 عصر
همون طور که مطالب و عنوانشونو میگیری از توی تگ IMAGE عکسشون رو هم parse کن.


<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>SoftArea51 - latest XML & CSS Utilities software for Windows</title>
<link>
http://www.softarea51.com/windows/Web_Development
/XML_CSS_Utilities/LatestReleases-1.html
</link>
<description>Try and buy latest XML & CSS Utilities software for Windows</description>
<language>en-us</language>
<image>
<title>SoftArea51 - latest XML & CSS Utilities software for Windows</title>
<url>http://www.softarea51.com/images/logo.gif</url>
<link>http://www.softarea51.com/</link>
<description>
Try and buy latest XML & CSS Utilities software for Windows
</description>
</image>
<item>
<title>Feed Mix</title>
<link>
http://www.softarea51.com/windows/Web_Development/
XML_CSS_Utilities/Review-Feed_Mix.html
</link>
<description>
Feed Mix is a feature-rich RSS editor with the unique
ability to create a new RSS feed from several others
that already exist...
</description>
</item>
<item>
<title>RSS Submit</title>
<link>
http://www.softarea51.com/windows/Web_Development/
XML_CSS_Utilities/Review-RSS_Submit.html
</link>
<description>
RSS Submit is the most powerful RSS feed
promotion tool available...
</description>
</item>
<item>
<title>PAD-Script</title>
<link>
http://www.softarea51.com/windows/Web_Development/
XML_CSS_Utilities/Review-PAD_Script.html
</link>
<description>
Avoid having to update all your PAD files whenever
the PAD format changes...
</description>
</item>
<item>
<title>PAD Data Extractor Tool</title>
<link>
http://www.softarea51.com/windows/Web_Development/
XML_CSS_Utilities/Review-PAD_Data_Extractor_Tool.html
</link>
<description>
Data Doctor XML PAD information extractor software
tools extract important data from online website
XML file...
</description>
</item>

</channel>
</rss>

p30graph3
پنج شنبه 15 بهمن 1388, 19:10 عصر
ببین کدم رو اینطوری تغییر دادم.

همش کار میکنه ولی عکس رو بازم نمیخونه


<?php

$RSS_Content = array();

function RSS_Tags($item, $type)
{
$y = array();
$tnl = $item->getElementsByTagName("title");
$tnl = $tnl->item(0);
$title = $tnl->firstChild->data;

$tnl = $item->getElementsByTagName("link");
$tnl = $tnl->item(0);
$link = $tnl->firstChild->data;

$tnl = $item->getElementsByTagName("image");
$tnl = $tnl->item(0);
$image = $tnl->firstChild->data;

$tnl = $item->getElementsByTagName("description");
$tnl = $tnl->item(0);
$description = $tnl->firstChild->data;

$y["title"] = $title;
$y["link"] = $link;
$y["image"] = $image;
$y["description"] = $description;
$y["type"] = $type;

return $y;
}


function RSS_Channel($channel)
{
global $RSS_Content;

$items = $channel->getElementsByTagName("item");

// Processing channel

$y = RSS_Tags($channel, 0); // get description of channel, type 0
array_push($RSS_Content, $y);

// Processing articles

foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}
}

function RSS_Retrieve($url)
{
global $RSS_Content;

$doc = new DOMDocument();
$doc->load($url);

$channels = $doc->getElementsByTagName("channel");

$RSS_Content = array();

foreach($channels as $channel)
{
RSS_Channel($channel);
}

}


function RSS_RetrieveLinks($url)
{
global $RSS_Content;

$doc = new DOMDocument();

$doc->load($url);

$channels = $doc->getElementsByTagName("channel");

$RSS_Content = array();

foreach($channels as $channel)
{
$items = $channel->getElementsByTagName("item");
foreach($items as $item)
{
$y = RSS_Tags($item, 1); // get description of article, type 1
array_push($RSS_Content, $y);
}

}

}


function RSS_Links($cat,$url, $size)
{
global $RSS_Content;


RSS_RetrieveLinks($url);
if($size > 0)
$recents = array_slice($RSS_Content, 0, $size);

foreach($recents as $article)
{
$type = $article["type"];
if($type == 0) continue;
$title = $article["title"];
$title = str_replace("'"," ",$title);
$title = trim ($title);
$link = $article["link"];
$image = $article["image"];
$desc = $article["description"];

$sit = explode('/',$link);
$site = $sit[2];
$sqk = mysql_query("select * from news where link = '$link' ") or die (mysql_error());
$nom = mysql_num_rows($sqk);
if($nom =='0') {
mysql_query("insert into news values('','$cat','$link','$title','$image') ") or die(mysql_error());
}
}



}


?>

امیـرحسین
پنج شنبه 15 بهمن 1388, 20:05 عصر
مگه نباید تگ url اون image رو بخونیم؟ شما محتویات تگ image رو میخونید که خودش شامل یه سری تگ دیگه است...

p30graph3
پنج شنبه 15 بهمن 1388, 21:10 عصر
میشه اون کد منو درست کنید!

امیـرحسین
پنج شنبه 15 بهمن 1388, 23:21 عصر
فکر کنم توی تابع RSS_Tags، اون خط image رو اینجوری تغییر بدید درست شه:
$tnl = $item->getElementsByTagName("image");
$tnl = $tnl->item(0);
$tnl = $tnl->getElementsByTagName("url");
$tnl = $tnl->item(0);
$image = $tnl->data;

p30graph3
جمعه 16 بهمن 1388, 12:21 عصر
نشد! اینطوری هم کردم ولی باز نشد!

p30graph3
جمعه 16 بهمن 1388, 13:59 عصر
دوستان کسی نیست یک کمک کوچولو بکنه این کد منو تکمیل کنه تا عکس هم از آر اس اس بگیره؟

p30graph3
جمعه 16 بهمن 1388, 20:44 عصر
دوستان این برای من خیلی واجبه خواهشا اگه میتونید کمک کنید دریغ نکنید

امیـرحسین
جمعه 16 بهمن 1388, 22:36 عصر
خط آخر کد من رو اینجوری کن ببین میشه:

$image = $tnl->firstChild->data;
اگه نشد. این کد رو اجرا کن ببین مشکل کجاست:

print_r($image); print_r($tnl);

p30graph3
شنبه 17 بهمن 1388, 11:23 صبح
مورد اول رو که خودم از اول اجرا کردم نشد.

کلا نشد!

p30graph3
شنبه 17 بهمن 1388, 15:52 عصر
اقا یکی کمک کنه خیلی واجبه

p30graph3
یک شنبه 18 بهمن 1388, 18:01 عصر
دوست عزیز نمیخام توهین کنم ولی اینجا انحمن ی برای یادگیریه

اگه من بلد بودم چه لزومی داشت بپرسم؟

کسی نیست جواب بده؟