<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
function getRandom() {
$("#random").hide();
$("#random").load("rsstoxml.php", '', callback);
}
function callback() {
$("#random").show();
setTimeout("getRandom();", 6000);
}
$(document).ready(getRandom);
</script>
</head>
<body>
<div id="random">
div content Here.......
</div>
</body>
</html>
Tuesday, February 8, 2011
rss feed to xml /Rss feed convert to xml format data
<?php
error_reporting(E_ALL);
// LOCATION OF THE FEED
$url = 'http://sports.espn.go.com/espn/rss/news';
//$url = 'http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/cricket/rss.xml';
// READ THE FEED
$xml = file_get_contents($url);
// CONVERT THE FEED TO AN OBJECT
$obj = SimpleXML_Load_String($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
// USE AN ITERATOR TO PRINT LINKS WITH THE ITEM TITLES
foreach ($obj->channel->item as $item)
{
$link = (string)$item->link;
$title = (string)$item->title;
$wrap_title= wordwrap($title, 62, "<br />");
$des = (string)$item->description;
$wrap_des = wordwrap($des, 79, "<br />");
if($url=="http://sports.espn.go.com/espn/rss/news")
{
$ini = strpos($wrap_des,"</a>");
$img_cut=substr($wrap_des,$ini);
}
else
{
$img_cut=$wrap_des;
}
echo "<div style='margin:0px auto;padding:0px;border:1px solid green;margin-bottom:20px;background:#CACACA;width:500px;'>";
echo "\n<a href=\"$link\">$wrap_title</a>";
echo "<br />";
echo "<div style='width:500px;'>$img_cut</div>";
echo "</div>";
}
?>
error_reporting(E_ALL);
// LOCATION OF THE FEED
$url = 'http://sports.espn.go.com/espn/rss/news';
//$url = 'http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/cricket/rss.xml';
// READ THE FEED
$xml = file_get_contents($url);
// CONVERT THE FEED TO AN OBJECT
$obj = SimpleXML_Load_String($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
// USE AN ITERATOR TO PRINT LINKS WITH THE ITEM TITLES
foreach ($obj->channel->item as $item)
{
$link = (string)$item->link;
$title = (string)$item->title;
$wrap_title= wordwrap($title, 62, "<br />");
$des = (string)$item->description;
$wrap_des = wordwrap($des, 79, "<br />");
if($url=="http://sports.espn.go.com/espn/rss/news")
{
$ini = strpos($wrap_des,"</a>");
$img_cut=substr($wrap_des,$ini);
}
else
{
$img_cut=$wrap_des;
}
echo "<div style='margin:0px auto;padding:0px;border:1px solid green;margin-bottom:20px;background:#CACACA;width:500px;'>";
echo "\n<a href=\"$link\">$wrap_title</a>";
echo "<br />";
echo "<div style='width:500px;'>$img_cut</div>";
echo "</div>";
}
?>
Wednesday, January 12, 2011
Display RSS with PHP
<?php header("Content-type: text/xml"); ?>
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; ?>
<rss version="2.0">
<channel>
<title>Website Title Here</title>
<?php
require_once("controller/dbconfig.php"); //change database configuration file
$con=new data(); //change class name and put your class
$connect=$con->connect(); //change function name and put your class
$query = "select * from video1 where status='2' order by date desc limit 5"; //change the query
$result=$con->execute($query);
while ($line = mysql_fetch_assoc($result))
{
$return[] = $line;
}
?>
<?php foreach ($return as $item) { ?>
<item>
<title><?php echo htmlentities($item['v_name']); ?></title> <!--Change table column name.[v_name] -->
<?php $id=$item['id']; ?> <!--Change table column name.[id] -->
<link><?php echo "http://yoursite.com/video.php?id=$id"; ?></link>
<description>
<![CDATA[
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width=20%>
<img src="<?php echo htmlentities($item['images']); ?>" width="80" height="80" /> <!--Change table column name.[images] -->
</td>
<td width=80% valign=top><?php echo htmlentities($item['description']);?></td> <!--Change table column name.[description] -->
</tr>
</table>
]]></description>
</item>
<?php } ?>
</channel>
</rss>
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; ?>
<rss version="2.0">
<channel>
<title>Website Title Here</title>
<?php
require_once("controller/dbconfig.php"); //change database configuration file
$con=new data(); //change class name and put your class
$connect=$con->connect(); //change function name and put your class
$query = "select * from video1 where status='2' order by date desc limit 5"; //change the query
$result=$con->execute($query);
while ($line = mysql_fetch_assoc($result))
{
$return[] = $line;
}
?>
<?php foreach ($return as $item) { ?>
<item>
<title><?php echo htmlentities($item['v_name']); ?></title> <!--Change table column name.[v_name] -->
<?php $id=$item['id']; ?> <!--Change table column name.[id] -->
<link><?php echo "http://yoursite.com/video.php?id=$id"; ?></link>
<description>
<![CDATA[
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width=20%>
<img src="<?php echo htmlentities($item['images']); ?>" width="80" height="80" /> <!--Change table column name.[images] -->
</td>
<td width=80% valign=top><?php echo htmlentities($item['description']);?></td> <!--Change table column name.[description] -->
</tr>
</table>
]]></description>
</item>
<?php } ?>
</channel>
</rss>
Subscribe to:
Comments (Atom)