Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div>
<?php
$rss = new SimpleXMLElement('http://www.naslovi.net/rss/sport/', null, true);
$ns = $rss->getNamespaces(true);
?><h1><a href='<?php echo $rss->channel->link; ?>'><?php echo $rss->channel->title; ?></a></h1>
<hr /><?php
foreach($rss->xpath('channel/item') as $item)
{
preg_match('/<img[^>]+>/', $item->children($ns['content'])->encoded, $match);
$item->image = $match[0];
$naslov = $item->title;
$link = $item->link;
$slika = $item->image;
$opis = $item->description;
$datum = $item->pubDate;
?>
<div><h2><a href='<?php echo $link;?>'><?php echo $naslov;?></a></h2></div>
<div><?php echo $opis; ?></br></div>
<div><?php echo $slika; ?></div>
<div></br>Objavljeno: <?php echo $datum;?></div>
<hr>
<?php
}
?>
</div>
</body>
</html>
To je za prikaz RSS Feed-a.
Kod za insert van petlje (samo jedan upit).
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div>
<?php
$rss = new SimpleXMLElement('http://www.naslovi.net/rss/sport/', null, true);
$ns = $rss->getNamespaces(true);
?><h1><a href='<?php echo $rss->channel->link; ?>'><?php echo $rss->channel->title; ?></a></h1>
<?php echo PHP_EOL?><hr /><?php echo PHP_EOL;
$sql = "INSERT INTO `rss_vesti` VALUES";
foreach($rss->xpath('channel/item') as $item)
{
preg_match('/<img[^>]+>/', $item->children($ns['content'])->encoded, $match);
$item->image = $match[0];
$naslov = $item->title;
$link = $item->link;
$slika = $item->image;
$opis = $item->description;
$datum = $item->pubDate;
$sql.="('','','".$naslov."','".$slika."','".$opis."','".$link."','".$datum."'),";
}
//KRAJ PETLJE - INSERT upit
$sql = substr($sql,0,-1).";";
$result = mysql_query($sql,$konekcija);
?>
</div>
</body>
</html>
I hope I didn't brain my damage - Homer
if (wife.position == kitchen) {return sandwich};