Rss with image: $image value
Posted: Wed Jun 08, 2011 11:10 am
I have 2 problems:
1. Image in rss reader.
I manage to read the image url, and to show it, but I have a problem when I read a variety of RSS feeds. the best you will see the problem on the link below
http://moravaprom.com/ebchost/
vait to open all rss source to the end, and then look at the latest to look at the end. in the latest rss reading I have all the same images an the end of rss item. I tried to solve this problem with $urlslike=""; (fortranslation $urlslike is $image... ) but with no success
2. speed of the code execution of
As you have seen, is slow is executed.
Note: This page was only for administrators, and not for visitors.
hiar is the code
[syntax=php]Code:
<?php
header('Content-Type: text/html; charset=utf-8');
$konekcija = mysql_connect("nesto", "nesto", "nesto") or die ("Parametri za povezivanje sa bazom nisu dobri, ili baza ne postoji!");
$baza = mysql_select_db("nesto", $konekcija) or die ("Na zalost, server nije u mogucnosti da pronadje bazu podataka!");
$sajtovi = mysql_query ("SELECT * FROM rss_sajtovi") or die(mysql_error());
while($row = mysql_fetch_array( $sajtovi ))
{
$id_sajta = $row['ID_SAJTA'];
$naziv = $row['NAZIV'];
$url = $row['URL'];
$rss = $row['RSS'];
$kategorija = $row['kategorija'];
echo "<h1>$id_sajta / $naziv / $url/ $rss / $kategorija </h1><hr></br>";
$rss = new SimpleXMLElement($rss, null, true);
foreach($rss->xpath('channel/item') as $item)
{
$dom = new DOMDocument();
@$dom->loadHTMLFile($item->link);
$xpath = new DOMXPath($dom);
$entries = $xpath->query('//div[@class="img"]//img');
foreach($entries as $e)
$image = "<img src='".$e->getAttribute("src")."'alt='' width='150'/>";
$naslov = $item->title;
$opis = $item->description;
$sadrzaj = $item->content;
$izvor = "<a href='{$item->link}'>{$rss->channel->title}</a>";
$url = $item->link;
$datum1 = $item->pubDate;
$datum2 = $item->pubdate;
$urlslike = $e->getAttribute("src");
echo "$naslov, $opis, $sadrzaj, $izvor,, $url, $datum1, $datum2, <img src='$urlslike'/> </br></br>";
$urlslike = "";
// this code is turn of for writing in database
//$sql="INSERT INTO rss_vesti VALUES('','$id_sajta','$naslov','$urlslike','$opis','$url','$datum2')";
//mysql_query($sql,$konekcija);
}
}
?>[/syntax]
1. Image in rss reader.
I manage to read the image url, and to show it, but I have a problem when I read a variety of RSS feeds. the best you will see the problem on the link below
http://moravaprom.com/ebchost/
vait to open all rss source to the end, and then look at the latest to look at the end. in the latest rss reading I have all the same images an the end of rss item. I tried to solve this problem with $urlslike=""; (fortranslation $urlslike is $image... ) but with no success
2. speed of the code execution of
As you have seen, is slow is executed.
Note: This page was only for administrators, and not for visitors.
hiar is the code
[syntax=php]Code:
<?php
header('Content-Type: text/html; charset=utf-8');
$konekcija = mysql_connect("nesto", "nesto", "nesto") or die ("Parametri za povezivanje sa bazom nisu dobri, ili baza ne postoji!");
$baza = mysql_select_db("nesto", $konekcija) or die ("Na zalost, server nije u mogucnosti da pronadje bazu podataka!");
$sajtovi = mysql_query ("SELECT * FROM rss_sajtovi") or die(mysql_error());
while($row = mysql_fetch_array( $sajtovi ))
{
$id_sajta = $row['ID_SAJTA'];
$naziv = $row['NAZIV'];
$url = $row['URL'];
$rss = $row['RSS'];
$kategorija = $row['kategorija'];
echo "<h1>$id_sajta / $naziv / $url/ $rss / $kategorija </h1><hr></br>";
$rss = new SimpleXMLElement($rss, null, true);
foreach($rss->xpath('channel/item') as $item)
{
$dom = new DOMDocument();
@$dom->loadHTMLFile($item->link);
$xpath = new DOMXPath($dom);
$entries = $xpath->query('//div[@class="img"]//img');
foreach($entries as $e)
$image = "<img src='".$e->getAttribute("src")."'alt='' width='150'/>";
$naslov = $item->title;
$opis = $item->description;
$sadrzaj = $item->content;
$izvor = "<a href='{$item->link}'>{$rss->channel->title}</a>";
$url = $item->link;
$datum1 = $item->pubDate;
$datum2 = $item->pubdate;
$urlslike = $e->getAttribute("src");
echo "$naslov, $opis, $sadrzaj, $izvor,, $url, $datum1, $datum2, <img src='$urlslike'/> </br></br>";
$urlslike = "";
// this code is turn of for writing in database
//$sql="INSERT INTO rss_vesti VALUES('','$id_sajta','$naslov','$urlslike','$opis','$url','$datum2')";
//mysql_query($sql,$konekcija);
}
}
?>[/syntax]