|
 |
|
อยากทราบวิธีเขียน RSS เพื่อส่งออก RSS ได้ โดยคนอื่นสามารถกดที่ add-on แล้วรับ RSS ได้ครับ |
|
 |
|
|
 |
 |
|
ลองเอาไปแก้ไขเพิ่มเติมนะครับ
Code (PHP)
<?
$arr = array();
$count = 0;
$block = "ITEM";
$key = "";
$value = "";
function startxml($parser, $name, $att) {
global $key;
$key = $name;
}
function endxml($parser, $name) {
global $count;
global $block;
if($name == $block) {
$count=$count+1;
}
}
function cdata($parser, $data) {
global $key;
global $value;
global $count;
global $arr;
if(strlen($data) >1) {
$value = $data;
$arr[$count]["$key"] = $value;
}
}
function openxml($url) {
$p = xml_parser_create();
xml_set_element_handler($p, "startxml", "endxml");
xml_set_character_data_handler($p, "cdata");
$fp = fopen($url ,"r");
while($data = fread($fp,4096)) {
xml_parse( $p, $data, feof($fp));
}
xml_parser_free($p);
}
openxml("http://www.manager.co.th/RSS/Home/Breakingnews.xml"); //url ของ rss
for($i = 0; $i < $count; $i ++) {
echo "<a target=_blank href=", $arr[$i]["LINK"],">"; //ส่วนการแสดงผล
echo $arr[$i]["TITLE"];
echo "</a>";
echo "<br><br>";
}
?>
ที่มา : http://www.webthaidd.com/php/webthaidd_article_747_.html
|
 |
 |
 |
 |
Date :
2011-05-24 09:49:12 |
By :
prach_kp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อีกอัน มี 2 ไฟล์นะครับ
1. ไฟล์ชื่อ "rss.html"
Code (PHP)
<html>
<head>
<script type="text/javascript">
function showRSS(str)
{
if (str.length==0)
{
document.getElementById("rssOutput").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("rssOutput").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getrss.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select onchange="showRSS(this.value)">
<option value="">Select an RSS-feed:</option>
<option value="Google">Google News</option>
<option value="MSNBC">MSNBC News</option>
</select>
</form>
<br />
<div id="rssOutput">RSS-feed will be listed here...</div>
</body>
</html>
2. ไฟล์ชื่อ "getrss.php"
Code (PHP)
<?php
//get the q parameter from URL
$q=$_GET["q"];
//find out which feed was selected
if($q=="Google")
{
$xml=("http://news.google.com/news?ned=us&topic=h&output=rss");
}
elseif($q=="MSNBC")
{
$xml=("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml");
}
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);
//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;
//output elements from "<channel>"
echo("<p><a href='" . $channel_link
. "'>" . $channel_title . "</a>");
echo("<br />");
echo($channel_desc . "</p>");
//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=2; $i++)
{
$item_title=$x->item($i)->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$item_link=$x->item($i)->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$item_desc=$x->item($i)->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;
echo ("<p><a href='" . $item_link
. "'>" . $item_title . "</a>");
echo ("<br />");
echo ($item_desc . "</p>");
}
?>
|
ประวัติการแก้ไข 2011-05-24 09:51:35
 |
 |
 |
 |
Date :
2011-05-24 09:51:13 |
By :
prach_kp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ ทำได้แล้ว ดีใจมากครับ
|
 |
 |
 |
 |
Date :
2011-05-24 15:55:54 |
By :
view2004 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|