ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ขอวิธีการทำ feed rss โดยดึงข้อมูลจาก sql ครับ  (อ่าน 7671 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
ayeweb
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 321
ออฟไลน์ ออฟไลน์

กระทู้: 5,205



ดูรายละเอียด เว็บไซต์
« เมื่อ: 26 กรกฎาคม 2009, 00:43:43 »

คือว่าหลังจากที่ลองค้นหาแล้วพยายามทำตามแล้ว มานักต่อนักก็เหลวครับ
ไม่สำเร็จสักทีขอแนวทางในการทำ rss โดยการดึงจาก sql 10 บทความล่าสุดมาแสดงครับ
ขอแบบละเอียดๆเลยนะครับ

ขอบคุณคงน้อยไป

ติด link ให้หน้าแรกของเว็บครับ
คนเข้าวันละประมาณ 1000 คน/วัน

ต้องการความช่วยเหลือจริงๆครับ

บันทึกการเข้า


ข่าวไอที ข่าวสารไอที แอพไอโฟน บริการอื่นๆ
บริการ ตรวจหวย อื่นๆ ทั่วไปสาระน่ารู้ ความรู้ต่างๆ
Host ไทย เว็บผู้หญิงนะคะ แต่ผู้ชายก็เข้าได้ค่ะ
ตรวจหวย
ตรวจหวย ผลสลากกินแบ่งรัฐบาล>>
เช่าโฮสติ้ง Ruk-com
ayeweb
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 321
ออฟไลน์ ออฟไลน์

กระทู้: 5,205



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 26 กรกฎาคม 2009, 01:26:58 »

ขอดันนะครับ  Cheesy Cheesy Cheesy
บันทึกการเข้า


ข่าวไอที ข่าวสารไอที แอพไอโฟน บริการอื่นๆ
บริการ ตรวจหวย อื่นๆ ทั่วไปสาระน่ารู้ ความรู้ต่างๆ
Host ไทย เว็บผู้หญิงนะคะ แต่ผู้ชายก็เข้าได้ค่ะ
ตรวจหวย
ตรวจหวย ผลสลากกินแบ่งรัฐบาล>>
เช่าโฮสติ้ง Ruk-com
bonaliza
Verified Seller
ก๊วนเสียว
*

พลังน้ำใจ: 21
ออฟไลน์ ออฟไลน์

กระทู้: 311



ดูรายละเอียด
« ตอบ #2 เมื่อ: 26 กรกฎาคม 2009, 02:45:16 »

แก้ข้อความนิดนึง

แหะๆ จำผิด

ใช้อันนี้ค่ะ
โค๊ด:
<?php
class RSSFeed {
// VARIABLES
    // channel vars
    
var $channel_url;
    var 
$channel_title;
    var 
$channel_description;
    var 
$channel_lang;
    var 
$channel_copyright;
    var 
$channel_date;
    var 
$channel_creator;
    var 
$channel_subject;   
    
// image
    
var $image_url;
    
// items
    
var $items = array();
    var 
$nritems;
   
// FUNCTIONS
    // constructor
    
function RSSFeed() {
         
$this->nritems=0;
        
$this->channel_url=&#39;&#39;;
        
$this->channel_title=&#39;&#39;;
        
$this->channel_description=&#39;&#39;;
        
$this->channel_lang=&#39;&#39;;
        
$this->channel_copyright=&#39;&#39;;
        
$this->channel_date=&#39;&#39;;
        
$this->channel_creator=&#39;&#39;;
        
$this->channel_subject=&#39;&#39;;
        
$this->image_url=&#39;&#39;;
    
}   
    
// set channel vars
    
function SetChannel($url$title$description$lang$copyright$creator$subject) {
        
$this->channel_url=$url;
        
$this->channel_title=$title;
        
$this->channel_description=$description;
        
$this->channel_lang=$lang;
        
$this->channel_copyright=$copyright;
        
$this->channel_date=date("Y-m-d").&#39;T&#39;.date("H:i:s").&#39;+01:00&#39;;
        
$this->channel_creator=$creator;
        
$this->channel_subject=$subject;
    }
    
// set image
    
function SetImage($url) {
        
$this->image_url=$url
    }
    
// set item
    
function SetItem($url$title$description) {
        
$this->items[$this->nritems][&#39;url&#39;]=$url;
        
$this->items[$this->nritems][&#39;title&#39;]=$title;
        
$this->items[$this->nritems][&#39;description&#39;]=$description;
        
$this->nritems++;   
    }
    
// output feed
    
function Output() {
        
$output =  &#39;<?xml version="1.0" encoding="utf-8"?>
'."\n";
        $output .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">'."\n";
        $output .= '<channel rdf:about="'.$this->channel_url.'">'."\n";
        $output .= '<title>'.$this->channel_title.'</title>'."\n";
        $output .= '<link>'.$this->channel_url.'</link>'."\n";
        $output .= '<description>'.$this->channel_description.'</description>'."\n";
        $output .= '<dc:language>'.$this->channel_lang.'</dc:language>'."\n";
        $output .= '<dc:rights>'.$this->channel_copyright.'</dc:rights>'."\n";
        $output .= '<dc:date>'.$this->channel_date.'</dc:date>'."\n";
        $output .= '<dc:creator>'.$this->channel_creator.'</dc:creator>'."\n";
        $output .= '<dc:subject>'.$this->channel_subject.'</dc:subject>'."\n";

        $output .= '<items>'."\n";
        $output .= '<rdf:Seq>';
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<rdf:li rdf:resource="'.$this->items[$k]['url'].'"/>'."\n";
        };  
        $output .= '</rdf:Seq>'."\n";
        $output .= '</items>'."\n";
        $output .= '<image rdf:resource="'.$this->image_url.'"/>'."\n";
        $output .= '</channel>'."\n";
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<item rdf:about="'.$this->items[$k]['url'].'">'."\n";
            $output .= '<title>'.$this->items[$k]['title'].'</title>'."\n";
            $output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
            $output .= '<description>'.$this->items[$k]['description'].'</description>'."\n";
            $output .= '<feedburner:origLink>'.$this->items[$k]['url'].'</feedburner:origLink>'."\n";
            $output .= '</item>'."\n";
        };
        $output .= '</rdf:RDF>'."\n";
        return $output;
    }
};

?>

แล้วเวลาใช้งาน ก็ประมาณนี้
โค๊ด:
               include("rss.php");
$myfeed = new RSSFeed();
$myfeed->SetChannel('http://yoururl.com',
 'title',
 'description',
 'th-th',
 'copyright',
 'creator',
 'subject');
$myfeed->SetImage('http://logourl.jpg');



$myfeed->SetItem("url page ปลายทาง",title,short_description); // จะให้มีกี่ข่าว ก็ SetItem ไปตามนั้น จะวนลูปเอาก็ได้




echo $myfeed->output(); // แสดงผลมันออกมา


งงมั๊ย
« แก้ไขครั้งสุดท้าย: 26 กรกฎาคม 2009, 03:00:33 โดย bonaliza » บันทึกการเข้า

------0_0-----
เกรียนพันธ์แท้
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 256
ออฟไลน์ ออฟไลน์

กระทู้: 4,376



ดูรายละเอียด
« ตอบ #3 เมื่อ: 26 กรกฎาคม 2009, 03:18:31 »

แก้ข้อความนิดนึง

แหะๆ จำผิด

ใช้อันนี้ค่ะ
โค๊ด:
<?php
class RSSFeed {
// VARIABLES
    // channel vars
    
var $channel_url;
    var 
$channel_title;
    var 
$channel_description;
    var 
$channel_lang;
    var 
$channel_copyright;
    var 
$channel_date;
    var 
$channel_creator;
    var 
$channel_subject;   
    
// image
    
var $image_url;
    
// items
    
var $items = array();
    var 
$nritems;
   
// FUNCTIONS
    // constructor
    
function RSSFeed() {
         
$this->nritems=0;
        
$this->channel_url=&#39;&#39;;
        
$this->channel_title=&#39;&#39;;
        
$this->channel_description=&#39;&#39;;
        
$this->channel_lang=&#39;&#39;;
        
$this->channel_copyright=&#39;&#39;;
        
$this->channel_date=&#39;&#39;;
        
$this->channel_creator=&#39;&#39;;
        
$this->channel_subject=&#39;&#39;;
        
$this->image_url=&#39;&#39;;
    
}   
    
// set channel vars
    
function SetChannel($url$title$description$lang$copyright$creator$subject) {
        
$this->channel_url=$url;
        
$this->channel_title=$title;
        
$this->channel_description=$description;
        
$this->channel_lang=$lang;
        
$this->channel_copyright=$copyright;
        
$this->channel_date=date("Y-m-d").&#39;T&#39;.date("H:i:s").&#39;+01:00&#39;;
        
$this->channel_creator=$creator;
        
$this->channel_subject=$subject;
    }
    
// set image
    
function SetImage($url) {
        
$this->image_url=$url
    }
    
// set item
    
function SetItem($url$title$description) {
        
$this->items[$this->nritems][&#39;url&#39;]=$url;
        
$this->items[$this->nritems][&#39;title&#39;]=$title;
        
$this->items[$this->nritems][&#39;description&#39;]=$description;
        
$this->nritems++;   
    }
    
// output feed
    
function Output() {
        
$output =  &#39;<?xml version="1.0" encoding="utf-8"?>
'."\n";
        $output .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">'."\n";
        $output .= '<channel rdf:about="'.$this->channel_url.'">'."\n";
        $output .= '<title>'.$this->channel_title.'</title>'."\n";
        $output .= '<link>'.$this->channel_url.'</link>'."\n";
        $output .= '<description>'.$this->channel_description.'</description>'."\n";
        $output .= '<dc:language>'.$this->channel_lang.'</dc:language>'."\n";
        $output .= '<dc:rights>'.$this->channel_copyright.'</dc:rights>'."\n";
        $output .= '<dc:date>'.$this->channel_date.'</dc:date>'."\n";
        $output .= '<dc:creator>'.$this->channel_creator.'</dc:creator>'."\n";
        $output .= '<dc:subject>'.$this->channel_subject.'</dc:subject>'."\n";

        $output .= '<items>'."\n";
        $output .= '<rdf:Seq>';
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<rdf:li rdf:resource="'.$this->items[$k]['url'].'"/>'."\n";
        };  
        $output .= '</rdf:Seq>'."\n";
        $output .= '</items>'."\n";
        $output .= '<image rdf:resource="'.$this->image_url.'"/>'."\n";
        $output .= '</channel>'."\n";
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<item rdf:about="'.$this->items[$k]['url'].'">'."\n";
            $output .= '<title>'.$this->items[$k]['title'].'</title>'."\n";
            $output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
            $output .= '<description>'.$this->items[$k]['description'].'</description>'."\n";
            $output .= '<feedburner:origLink>'.$this->items[$k]['url'].'</feedburner:origLink>'."\n";
            $output .= '</item>'."\n";
        };
        $output .= '</rdf:RDF>'."\n";
        return $output;
    }
};

?>

แล้วเวลาใช้งาน ก็ประมาณนี้
โค๊ด:
               include("rss.php");
$myfeed = new RSSFeed();
$myfeed->SetChannel('http://yoururl.com',
 'title',
 'description',
 'th-th',
 'copyright',
 'creator',
 'subject');
$myfeed->SetImage('http://logourl.jpg');



$myfeed->SetItem("url page ปลายทาง",title,short_description); // จะให้มีกี่ข่าว ก็ SetItem ไปตามนั้น จะวนลูปเอาก็ได้




echo $myfeed->output(); // แสดงผลมันออกมา


งงมั๊ย



ไม่เข้าใจอะคับ ไฟล์ตั้งชื่อยังไง
บันทึกการเข้า

ห้ามใส่ลายเซนต์เกี่ยวกับการเมือง
navico
Verified Seller
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 108
ออฟไลน์ ออฟไลน์

กระทู้: 2,315



ดูรายละเอียด เว็บไซต์
« ตอบ #4 เมื่อ: 26 กรกฎาคม 2009, 03:52:36 »

แก้ข้อความนิดนึง

แหะๆ จำผิด

ใช้อันนี้ค่ะ
โค๊ด:
<?php
class RSSFeed {
// VARIABLES
    // channel vars
    
var $channel_url;
    var 
$channel_title;
    var 
$channel_description;
    var 
$channel_lang;
    var 
$channel_copyright;
    var 
$channel_date;
    var 
$channel_creator;
    var 
$channel_subject;   
    
// image
    
var $image_url;
    
// items
    
var $items = array();
    var 
$nritems;
   
// FUNCTIONS
    // constructor
    
function RSSFeed() {
         
$this->nritems=0;
        
$this->channel_url=&#39;&#39;;
        
$this->channel_title=&#39;&#39;;
        
$this->channel_description=&#39;&#39;;
        
$this->channel_lang=&#39;&#39;;
        
$this->channel_copyright=&#39;&#39;;
        
$this->channel_date=&#39;&#39;;
        
$this->channel_creator=&#39;&#39;;
        
$this->channel_subject=&#39;&#39;;
        
$this->image_url=&#39;&#39;;
    
}   
    
// set channel vars
    
function SetChannel($url$title$description$lang$copyright$creator$subject) {
        
$this->channel_url=$url;
        
$this->channel_title=$title;
        
$this->channel_description=$description;
        
$this->channel_lang=$lang;
        
$this->channel_copyright=$copyright;
        
$this->channel_date=date("Y-m-d").&#39;T&#39;.date("H:i:s").&#39;+01:00&#39;;
        
$this->channel_creator=$creator;
        
$this->channel_subject=$subject;
    }
    
// set image
    
function SetImage($url) {
        
$this->image_url=$url
    }
    
// set item
    
function SetItem($url$title$description) {
        
$this->items[$this->nritems][&#39;url&#39;]=$url;
        
$this->items[$this->nritems][&#39;title&#39;]=$title;
        
$this->items[$this->nritems][&#39;description&#39;]=$description;
        
$this->nritems++;   
    }
    
// output feed
    
function Output() {
        
$output =  &#39;<?xml version="1.0" encoding="utf-8"?>
'."\n";
        $output .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">'."\n";
        $output .= '<channel rdf:about="'.$this->channel_url.'">'."\n";
        $output .= '<title>'.$this->channel_title.'</title>'."\n";
        $output .= '<link>'.$this->channel_url.'</link>'."\n";
        $output .= '<description>'.$this->channel_description.'</description>'."\n";
        $output .= '<dc:language>'.$this->channel_lang.'</dc:language>'."\n";
        $output .= '<dc:rights>'.$this->channel_copyright.'</dc:rights>'."\n";
        $output .= '<dc:date>'.$this->channel_date.'</dc:date>'."\n";
        $output .= '<dc:creator>'.$this->channel_creator.'</dc:creator>'."\n";
        $output .= '<dc:subject>'.$this->channel_subject.'</dc:subject>'."\n";

        $output .= '<items>'."\n";
        $output .= '<rdf:Seq>';
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<rdf:li rdf:resource="'.$this->items[$k]['url'].'"/>'."\n";
        };  
        $output .= '</rdf:Seq>'."\n";
        $output .= '</items>'."\n";
        $output .= '<image rdf:resource="'.$this->image_url.'"/>'."\n";
        $output .= '</channel>'."\n";
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<item rdf:about="'.$this->items[$k]['url'].'">'."\n";
            $output .= '<title>'.$this->items[$k]['title'].'</title>'."\n";
            $output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
            $output .= '<description>'.$this->items[$k]['description'].'</description>'."\n";
            $output .= '<feedburner:origLink>'.$this->items[$k]['url'].'</feedburner:origLink>'."\n";
            $output .= '</item>'."\n";
        };
        $output .= '</rdf:RDF>'."\n";
        return $output;
    }
};

?>

แล้วเวลาใช้งาน ก็ประมาณนี้
โค๊ด:
               include("rss.php");
$myfeed = new RSSFeed();
$myfeed->SetChannel('http://yoururl.com',
 'title',
 'description',
 'th-th',
 'copyright',
 'creator',
 'subject');
$myfeed->SetImage('http://logourl.jpg');



$myfeed->SetItem("url page ปลายทาง",title,short_description); // จะให้มีกี่ข่าว ก็ SetItem ไปตามนั้น จะวนลูปเอาก็ได้




echo $myfeed->output(); // แสดงผลมันออกมา


งงมั๊ย



ไม่เข้าใจอะคับ ไฟล์ตั้งชื่อยังไง

อันแีรก ก็ rss.php
อัน 2 ตามอารมณ์
บันทึกการเข้า
bonaliza
Verified Seller
ก๊วนเสียว
*

พลังน้ำใจ: 21
ออฟไลน์ ออฟไลน์

กระทู้: 311



ดูรายละเอียด
« ตอบ #5 เมื่อ: 26 กรกฎาคม 2009, 03:58:48 »

แก้ข้อความนิดนึง

แหะๆ จำผิด

ใช้อันนี้ค่ะ
อันนี้ ตั้งชื่อเป็น rss.php
โค๊ด:
<?php
class RSSFeed {
// VARIABLES
    // channel vars
    
var $channel_url;
    var 
$channel_title;
    var 
$channel_description;
    var 
$channel_lang;
    var 
$channel_copyright;
    var 
$channel_date;
    var 
$channel_creator;
    var 
$channel_subject;   
    
// image
    
var $image_url;
    
// items
    
var $items = array();
    var 
$nritems;
   
// FUNCTIONS
    // constructor
    
function RSSFeed() {
         
$this->nritems=0;
        
$this->channel_url=&#39;&#39;;
        
$this->channel_title=&#39;&#39;;
        
$this->channel_description=&#39;&#39;;
        
$this->channel_lang=&#39;&#39;;
        
$this->channel_copyright=&#39;&#39;;
        
$this->channel_date=&#39;&#39;;
        
$this->channel_creator=&#39;&#39;;
        
$this->channel_subject=&#39;&#39;;
        
$this->image_url=&#39;&#39;;
    
}   
    
// set channel vars
    
function SetChannel($url$title$description$lang$copyright$creator$subject) {
        
$this->channel_url=$url;
        
$this->channel_title=$title;
        
$this->channel_description=$description;
        
$this->channel_lang=$lang;
        
$this->channel_copyright=$copyright;
        
$this->channel_date=date("Y-m-d").&#39;T&#39;.date("H:i:s").&#39;+01:00&#39;;
        
$this->channel_creator=$creator;
        
$this->channel_subject=$subject;
    }
    
// set image
    
function SetImage($url) {
        
$this->image_url=$url
    }
    
// set item
    
function SetItem($url$title$description) {
        
$this->items[$this->nritems][&#39;url&#39;]=$url;
        
$this->items[$this->nritems][&#39;title&#39;]=$title;
        
$this->items[$this->nritems][&#39;description&#39;]=$description;
        
$this->nritems++;   
    }
    
// output feed
    
function Output() {
        
$output =  &#39;<?xml version="1.0" encoding="utf-8"?>
'."\n";
        $output .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">'."\n";
        $output .= '<channel rdf:about="'.$this->channel_url.'">'."\n";
        $output .= '<title>'.$this->channel_title.'</title>'."\n";
        $output .= '<link>'.$this->channel_url.'</link>'."\n";
        $output .= '<description>'.$this->channel_description.'</description>'."\n";
        $output .= '<dc:language>'.$this->channel_lang.'</dc:language>'."\n";
        $output .= '<dc:rights>'.$this->channel_copyright.'</dc:rights>'."\n";
        $output .= '<dc:date>'.$this->channel_date.'</dc:date>'."\n";
        $output .= '<dc:creator>'.$this->channel_creator.'</dc:creator>'."\n";
        $output .= '<dc:subject>'.$this->channel_subject.'</dc:subject>'."\n";

        $output .= '<items>'."\n";
        $output .= '<rdf:Seq>';
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<rdf:li rdf:resource="'.$this->items[$k]['url'].'"/>'."\n";
        };  
        $output .= '</rdf:Seq>'."\n";
        $output .= '</items>'."\n";
        $output .= '<image rdf:resource="'.$this->image_url.'"/>'."\n";
        $output .= '</channel>'."\n";
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<item rdf:about="'.$this->items[$k]['url'].'">'."\n";
            $output .= '<title>'.$this->items[$k]['title'].'</title>'."\n";
            $output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
            $output .= '<description>'.$this->items[$k]['description'].'</description>'."\n";
            $output .= '<feedburner:origLink>'.$this->items[$k]['url'].'</feedburner:origLink>'."\n";
            $output .= '</item>'."\n";
        };
        $output .= '</rdf:RDF>'."\n";
        return $output;
    }
};

?>

แล้วเวลาใช้งาน ก็ประมาณนี้
โค๊ด:
               include("rss.php");
$myfeed = new RSSFeed();
$myfeed->SetChannel('http://yoururl.com',
 'title',
 'description',
 'th-th',
 'copyright',
 'creator',
 'subject');
$myfeed->SetImage('http://logourl.jpg');



$myfeed->SetItem("url page ปลายทาง",title,short_description); // จะให้มีกี่ข่าว ก็ SetItem ไปตามนั้น จะวนลูปเอาก็ได้




echo $myfeed->output(); // แสดงผลมันออกมา


งงมั๊ย



ก้อนแรก เป็นชุดคำสั่งเอาไว้ใช้งาน เราตั้งชื่ออะไรก็ได้
แต่ตัวอย่าง ตั้ง นามสมมติว่า rss.php
โค๊ด:
<?php
class RSSFeed {
// VARIABLES
    // channel vars
    
var $channel_url;
    var 
$channel_title;
    var 
$channel_description;
    var 
$channel_lang;
    var 
$channel_copyright;
    var 
$channel_date;
    var 
$channel_creator;
    var 
$channel_subject;   
    
// image
    
var $image_url;
    
// items
    
var $items = array();
    var 
$nritems;
   
// FUNCTIONS
    // constructor
    
function RSSFeed() {
         
$this->nritems=0;
        
$this->channel_url=&#39;&#39;;
        
$this->channel_title=&#39;&#39;;
        
$this->channel_description=&#39;&#39;;
        
$this->channel_lang=&#39;&#39;;
        
$this->channel_copyright=&#39;&#39;;
        
$this->channel_date=&#39;&#39;;
        
$this->channel_creator=&#39;&#39;;
        
$this->channel_subject=&#39;&#39;;
        
$this->image_url=&#39;&#39;;
    
}   
    
// set channel vars
    
function SetChannel($url$title$description$lang$copyright$creator$subject) {
        
$this->channel_url=$url;
        
$this->channel_title=$title;
        
$this->channel_description=$description;
        
$this->channel_lang=$lang;
        
$this->channel_copyright=$copyright;
        
$this->channel_date=date("Y-m-d").&#39;T&#39;.date("H:i:s").&#39;+01:00&#39;;
        
$this->channel_creator=$creator;
        
$this->channel_subject=$subject;
    }
    
// set image
    
function SetImage($url) {
        
$this->image_url=$url
    }
    
// set item
    
function SetItem($url$title$description) {
        
$this->items[$this->nritems][&#39;url&#39;]=$url;
        
$this->items[$this->nritems][&#39;title&#39;]=$title;
        
$this->items[$this->nritems][&#39;description&#39;]=$description;
        
$this->nritems++;   
    }
    
// output feed
    
function Output() {
        
$output =  &#39;<?xml version="1.0" encoding="utf-8"?>
'."\n";
        $output .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">'."\n";
        $output .= '<channel rdf:about="'.$this->channel_url.'">'."\n";
        $output .= '<title>'.$this->channel_title.'</title>'."\n";
        $output .= '<link>'.$this->channel_url.'</link>'."\n";
        $output .= '<description>'.$this->channel_description.'</description>'."\n";
        $output .= '<dc:language>'.$this->channel_lang.'</dc:language>'."\n";
        $output .= '<dc:rights>'.$this->channel_copyright.'</dc:rights>'."\n";
        $output .= '<dc:date>'.$this->channel_date.'</dc:date>'."\n";
        $output .= '<dc:creator>'.$this->channel_creator.'</dc:creator>'."\n";
        $output .= '<dc:subject>'.$this->channel_subject.'</dc:subject>'."\n";

        $output .= '<items>'."\n";
        $output .= '<rdf:Seq>';
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<rdf:li rdf:resource="'.$this->items[$k]['url'].'"/>'."\n";
        };   
        $output .= '</rdf:Seq>'."\n";
        $output .= '</items>'."\n";
        $output .= '<image rdf:resource="'.$this->image_url.'"/>'."\n";
        $output .= '</channel>'."\n";
        for($k=0; $k<$this->nritems; $k++) {
            $output .= '<item rdf:about="'.$this->items[$k]['url'].'">'."\n";
            $output .= '<title>'.$this->items[$k]['title'].'</title>'."\n";
            $output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
            $output .= '<description>'.$this->items[$k]['description'].'</description>'."\n";
            $output .= '<feedburner:origLink>'.$this->items[$k]['url'].'</feedburner:origLink>'."\n";
            $output .= '</item>'."\n";
        };
        $output .= '</rdf:RDF>'."\n";
        return $output;
    }
};


ก้อนที่สอง เป็นสคริปสำหรับหน้าที่คุณต้องการให้มันกลายเป็น feed
ตั้งชื่อสมมติไว้ว่า feed.php


โค๊ด:
                include("rss.php");
$myfeed = new RSSFeed();
$myfeed->SetChannel('http://yoururl.com',
  'title',
  'description',
  'th-th',
  'copyright',
  'creator',
  'subject');
$myfeed->SetImage('http://logourl.jpg');



$myfeed->SetItem("url page ปลายทาง",title,short_description); // จะให้มีกี่ข่าว ก็ SetItem ไปตามนั้น จะวนลูปเอาก็ได้




echo $myfeed->output(); // แสดงผลมันออกมา


แล้วในหน้านี้ คุณต้องการให้มันฟีดอะไรออกมา ก็เอาไปใส่ตรง
อ้างถึง
$myfeed->SetItem("url page ปลายทาง",title,short_description); // จะให้มีกี่ข่าว ก็ SetItem ไปตามนั้น จะวนลูปเอาก็ได้


ประมาณนี้
บันทึกการเข้า

------0_0-----
ayeweb
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 321
ออฟไลน์ ออฟไลน์

กระทู้: 5,205



ดูรายละเอียด เว็บไซต์
« ตอบ #6 เมื่อ: 26 กรกฎาคม 2009, 12:31:37 »

คือว่าต้องการแบบดึงมาจาก sql โดยตรงเลยน่ะครับ
เช่น เขียนบทความขึ้นมันก็มาเลย
อันนี้ไม่เห็นมีการเชื่อมต่อ ดาต้าเบสเลยครับ
แอด msnมาคุยกันก่อนก็ได้นะครับ
บันทึกการเข้า


ข่าวไอที ข่าวสารไอที แอพไอโฟน บริการอื่นๆ
บริการ ตรวจหวย อื่นๆ ทั่วไปสาระน่ารู้ ความรู้ต่างๆ
Host ไทย เว็บผู้หญิงนะคะ แต่ผู้ชายก็เข้าได้ค่ะ
ตรวจหวย
ตรวจหวย ผลสลากกินแบ่งรัฐบาล>>
เช่าโฮสติ้ง Ruk-com
ifeelingz
สมุนแก๊งเสียว
*

พลังน้ำใจ: 60
ออฟไลน์ ออฟไลน์

กระทู้: 569



ดูรายละเอียด
« ตอบ #7 เมื่อ: 26 พฤษภาคม 2010, 14:28:02 »

คือขอโทษนะครับที่ขุดขึ้นมา หาคนมาตอบเพิ่มเติมอ่ะครับมันยังไม่ จบ

สนใจจจจ T^T  Cry
บันทึกการเข้า
phuketbutler
คนรักเสียว
*

พลังน้ำใจ: 3
ออฟไลน์ ออฟไลน์

กระทู้: 167



ดูรายละเอียด เว็บไซต์
« ตอบ #8 เมื่อ: 26 พฤษภาคม 2010, 15:27:30 »

อื้มม มีประโยชน์  wanwan013
บันทึกการเข้า

mint506452
คนรักเสียว
*

พลังน้ำใจ: 5
ออฟไลน์ ออฟไลน์

กระทู้: 168



ดูรายละเอียด เว็บไซต์
« ตอบ #9 เมื่อ: 26 พฤษภาคม 2010, 15:37:03 »

ขอบคุณครับ Cry Cry Cry
บันทึกการเข้า

BlueDragon
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 89
ออฟไลน์ ออฟไลน์

กระทู้: 1,778



ดูรายละเอียด เว็บไซต์
« ตอบ #10 เมื่อ: 19 กรกฎาคม 2010, 23:16:46 »

ขออนุญาตขุดขึ้นมานะค่ะ
สนใจค่ะ แต่ยังงงอยู่ว่าเอาไปใช้งานยังไง

 Cry
บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์